2007-06-21

Using ASP.Net user controls ASCX in MOSS/WSSv3


Chris Johnson has posted a great article on using ASP.Net ASCX user controls in MOSS/WSSv3. I have been recently creating custom controls in Visual Studio (i.e. Control Classes not ASCX). To use these I add the controls to the GAC and then add an entry to the web.config to make it a safe control. The benefit of the ASCX model is that you can develop the user control in a more visual manner.


The ASCX controls can be used in MOSS/WSSv3 via the following method:



1. Create a Directory called “usercontrols” in the root of your sharepoint web site on the file system E.g. C:\Inetpub\wwwroot\wss\VirtualDirectories\moss.litwareinc.com80\UserControls


2. Open IIS manager and in the root of your SharePoint site create a VirtualDirectory called “_controls” and point it to that newly created directory.


3. Put your user control in that newly created directory on the filesystem


4. Open the web.config file and add the following:


<SafeControl src="~/_controls/*" mce_src="~/_controls/*" IncludeSubFolders="True" Safe="True" AllowRemoteDesigner="True" /">


5. In your ASPX page add the following:


<%@ Register src="~/_controls/SomeControl.ascx" mce_src="~/_controls/SomeControl.ascx" TagName="somecontrol" TagPrefix="uc2" %">


And…


<uc2:somecontrol id="mycontrol1" runat="server"></uc2:somecontrol>


6. Run your ASPX page and your control should render correctly.





No comments :

Post a comment