Use your ASP .NET WebControl in MOSS 2007 with Sharepoint Delegate Control
In the new release of Sharepoint Server (MOSS 2007), a very interesting control is provided, "DelegateControl", under Microsoft.SharePoint.WebControls.SPControl. With this control we can easily reuse our ASP.NET control on SPS pages. Now, an ASP .NET programmer can name himself a "part time SPS Web part developer" :)
Here is sample on how you can use DelegateControl on a sharepoint page:
1 . Create an ASP .NET WebControl (ASPNETControl.ascx) file as following:
<%@ Control Language="C#" AutoEventWireup="true" ClassName="ASPNETControl" %>
<script runat ="server" >
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = System.DateTime.Now.ToShortDateString();
}
</script>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
2. Create a folder "ASPNETControl" under:
\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES
And Copy the file (ASPNETControl.ascx) to this folder.
3. Create two xml file feature.xml (fixed name, must be feature.xml) and Control.xml:
Feature.xml:
<?xml version="1.0" encoding="utf-8" ?>
<Feature Id="62D5F317-A793-4328-A250-50CBE1F5B70E"
Title="ASPNETControl"
Scope="Farm"
Description="Test ASPNET control"
Version="1.0.0.0"
xmlns="https://schemas.microsoft.com/sharepoint/" >
<ElementManifests>
<ElementManifest Location="Control.xml" />
</ElementManifests>
</Feature>
Control.xml:
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="https://schemas.microsoft.com/sharepoint/" >
<Control Id="ASPNETControl"
ControlSrc="~/_ControlTemplates/ASPNETControl/ASPNETControl.ascx"
Sequence="100" >
</Control>
</Elements>
4. Create a folder "ASPNETControl" under following folder:
\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES
And copy the two XML files into it.
5. Execute stsadm.exe to run following command:
Stsadm -o installfeature -filename ASPNETControl\feature.xml -force
6. Open Sharepoint 3.0 central Administration, in
Central Administration>Operations>Global Configuration>Manage Farm Features
You will notice this new feature has been enabled by default
7. Open your site with SharePoint Designer 2007, and add following line in the default.aspx:
<SharePoint:DelegateControl ControlId="ASPNETControl" RunAt="server" />
Save the page, and view your site again. You will see the control has been updated on it.
Additionally, for those ASP .NET controls with code behind, you need to copy the .cs or .vb file with the .ascx file
Comments
Anonymous
December 20, 2006
Question: What about codebehind-files? If this is allowed, where and how to deploy those? TanxAnonymous
December 27, 2006
As I mentioned, with code behind files: you need to copy the .cs or .vb file with the .ascx fileAnonymous
January 08, 2007
After executing the stasdm.exe my new feature got enabled in the Sharepoint 3.0 Central Administration page. But in my sharepoint site am getting error message like "Critical error encountered in this page". Can you help me out to figure out this issue? Thanks in Advance...Anonymous
January 11, 2007
Interesting! But i dont want to edit a page in SharePoint Designer to insert the control on a production enviroment. How do i save the edited page in my development enviroment and redeploy it on the production enviroment (on a specific site)?Anonymous
January 21, 2007
i have developed an user control that uses xml, css and js files where do i put these files when i deploy the user control to moss 2007?Anonymous
February 14, 2007
What about the dlls that are created by ASP.Net user control ? Does sharepoint compile the sources 'on-the-fly' to generate these dlls? Secondly, this feature cannot be a web-part feature, correct?Anonymous
March 07, 2007
The moment i install this "Stsadm -o installfeature -filename ASPNETControlfeature.xml -force" and Open Sharepoint 3.0 central Administration and go to Central Administration>Operations>Global Configuration>Manage Farm Features it is giving following error "You are not authorized to view this page"Anonymous
April 02, 2007
<a href= http://ugo.italy-forum.info/index.html >ugo.italy-forum.info</a> <a href= http://egle.italy-forum.info/index.html >egle.italy-forum.info</a> <a href= http://rosa.italy-forum.info/index.html >rosa.italy-forum.info</a> <a href= http://gesu.italy-forum.info/index.html >gesu.italy-forum.info</a> <a href= http://igor.italy-forum.info/index.html >igor.italy-forum.info</a>Anonymous
April 10, 2007
<a href= http://four.fsphost.com/sdas/britney-spears-oops.html|britney spears oops ></a> [url=http://four.fsphost.com/sdas/britney-spears-oops.html|britney spears oops][/url]Anonymous
June 12, 2007
Friend you could help me, I could initiate in the administrator of sharepoint the user control “ASPNETControl”, but I cannot use it in the page, leaves to me that “SharePoint: DelegateControl” is not compatible with IE, my mail is jonathan_moscosos@hotmail.comAnonymous
December 27, 2007
Hi, I had followed all steps. On inserting the DelegateControl in my default.aspx of MOSS site, It is not display the usercontrol on refreshing the site. I am even not getting any kind of error in my eventlog. Can you plz let me know where can the problem be ?Anonymous
March 01, 2008
Hi, i had followed all steps . but the delegate control is not visible. can you help me please, to resolve this trouble.Anonymous
March 02, 2008
The comment has been removedAnonymous
August 13, 2008
Yes, the tag is there but the UC is not visible. If I change the ControlId to SmallSearchInputBox it starts working. If I change it to AnyNonExistingThing nothing happens, no error is raised and obviously nothing is visible. I see the feature at operations level perfectly but only there.