Friday, June 3, 2011

Deploying A User Control In SharePoint Site

1) Create a web application called SharedUserControls.

2) Remove your web.config and default.aspx page.

3) Create a web user control called (.ascx page) in the same project and add whichever controls you want to add in this web user control.




In the Source of your user control(ascx page) include the ClassName attribute, for classname, give any name with any extension. Here the classname is MyCntrl.as



4) Here we have created a text box, a label and a button which displays the textbox text on button click in the label.
5) Add the web deployment project to the same project by selecting "Add Web Project Project..." from the Build menu. In Vsts 2008, you will need an extension for Adding Web Deployment Project. Download the same and then this option will be available inside the Build Menu.


6) It will create a new web deployment project, Keep the default name as it is and click OK.



7) Double click the new project to get the project property pages.

Uncheck the last check box - "Allow this precompiled site to be updatable".
8) Go to the "Output Assemblies" tab
9) Select "Merge all pages and control outputs to a single assembly"
10) Call the assembly name: "SharedUserControlMerged”



Assign strong names to both the dlls(i.e. both for the user controls(SharedUserControls.dll and the SharedUserMerged.dll)
11) Build the solution and put the SharedUserControlMerged.dll into the GAC.
12) Open the Sharepoint designer site where you want to use the User Control(aspx page)
13) Register the UserControl, by adding the code

<%@ Register tagprefix="PrintfuncLibrary" namespace="MyCtrl" assembly="SharedUserControlMerged, Version=1.0.0.0, Culture=neutral, PublicKeyToken=af7fd7f230293b2e" %>

14) Once registered, add the UserControl, in the place of your choice by adding the following code.
Next to the tag prefix , give the same extension that you gave in your user control source. Here the extension used was as.

<form id="form1" runat="server">
<?XML:NAMESPACE PREFIX = PrintfuncLibrary /><printfunclibrary:as id="SharedUserControls" runat="server"></form>

16) In the web.config of your sharepoint site, Register your assembly as a safe control. The namespace will be the same as the className in the source of your User Control(ascx page) and assembly name and Public Token Key will be that of the Merged dll that you put in the GAC.

<safecontrols>
<safecontrol allowremotedesigner="True" safe="True" typename="*" namespace="MyCtrl" assembly="SharedUserControlMerged, Version=1.0.0.0, Culture=neutral, PublicKeyToken=af7fd7f230293b2e">

17) Preview your sharepoint site in the browser, you will notice that the user control you deployed in asp.net appears in the sharepoint site.

No comments:

Post a Comment