Home > Development, Microsoft Office SharePoint Server 2007 > How to wrap a user control inside web part using WSP Builder

How to wrap a user control inside web part using WSP Builder

How to wrap a user control inside web part using WSP Builder

Here , I describe a simple way for wrapping ASP.NET user control inside web part for deployment to SharePoint using WSP builder.

1-     Create WSP Project

a-      Firstly, you need to have WSP Builder Package to be deployed on your development environment.

b-     Open visual studio , from File menu, select New -> Project , Select WSPBuilder from project type pane , in the name box type GSWebpart.

2-     Create New WebPart with Feature

a-      In visual studio, Right click on GSWebPart Project, and point to Add, and then click New Item…

b-     In the Categories pane, click WSPBuilder. In the Templates pane, click Web Part Feature. In the Name box, type ConverterWebPart, and then click OK.

c-      In the Feature Settings dialog, type My Web Part for the Title, A web part built using WSPBuilder for the Description and set the Scope to be Site. Click OK.

 

3-     Adding ASP.NET Project Types to the WSPBuilder Project

a-      In visual studio, right click on GSWePart Project , select unload project.

b-     In visual studio, right click on GSWePart Project , select Edit project.

c-      Locate the ProjectTypeGuids element and add the ASP.NET web application project type guid {349C5851-65DF-11DA-9384-00065B846F21}.

d-     Save and then close the GSWePart.csproj file.

e-      Right-click on the GSWePart project and select Reload Project.

f-       Right-click on the GSWePart project and select Properties On the Application tab, change the Target Framework to be .NET Framework 3.5. Save the changes

 

4-     Creating Web User Control

a-      In visual studio, right click on Template Folder, then point to add then select new folder , rename it to CONTROLTEMPLATES.

b-     Right click on CONTROLTEMPLATES folder , then point to add then select new folder , rename it to GSWebPart.

c-       Right-click the GSWebPart folder, select Add then click New Item.

d-     In the Categories pane, click Web. In the Templates pane, click Web User Control. Name the control  ConverterWebPartUserControl.ascx, and then click Add.

e-      Delete the CodeBehind attribute in the ConverterWebPartUserControl.ascx file. Replace the Inherits attribute with GSWebPart. ConverterWebPartUserControl, GSWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=[your PublicKeyToken]. The following code shows the corrected file:

f-       <%@ Control Language=”C#” AutoEventWireup=”true” Inherits=” GSWebPart. ConverterWebPartUserControl, GSWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9410bf5b454f3bbd” %>

g-      Open the ConverterWebPartUserControl.ascx file in the designer view. Click the Toolbox, and then add a Label using a drag-and-drop operation. Switch to the code view and rename the ID property to be MyLabel and add “SharePoint” as text property

h-     Open the MyWebUserControl.ascx.cs file and the MyWebUserControl.ascx.designer.cs file. Change the namespace to GSWebPart in both files.

 

 

5-     Wrapping the User Control and Connecting the Properties

This procedure demonstrates how to wrap the user control inside the web part and connect the properties between SharePoint, the web wart and the user control.

To wrap the user control and connect the properties

a-      Open the ConverterWebPart.cs file.

b-     Within the CreateChildControls() method, delete the single line of code under the // Your code here… comment. Enter code to load the MyWebUserControl, assign the value of MyProperty to the DisplayText property of the control and then add the control to the web part’s Controls collection. The code below demonstrates how to do this:

// Your code here…

ConverterWebPartUserControl myControl =

(ConverterWebPartUserControl)Page.LoadControl(“~/_controltemplates/MyWebPart/MyWebUserControl.ascx”);

this.Controls.Add(myControl);

c-      Right-click on the MyWebPart solution and select Rebuild Solution

Advertisements
  1. June 16, 2013 at 12:03 am

    Write more, thats all I have to say. Literally,
    it seems as though you relied on the video to make your point.

    You definitely know what youre talking about,
    why waste your intelligence on just posting videos
    to your weblog when you could be giving us something informative to read?

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: