Welcome to MSDN Blogs Sign in | Join | Help

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="http://schemas.microsoft.com/sharepoint/" >

  <ElementManifests>

      <ElementManifest Location="Control.xml" />

  </ElementManifests>

</Feature>

 Control.xml:

 

<?xml version="1.0" encoding="utf-8" ?>

<Elements xmlns="http://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

Published Friday, December 08, 2006 7:45 AM by MSDNTST

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

Thursday, December 21, 2006 5:12 AM by P.

# re: Use your ASP .NET WebControl in MOSS 2007 with Sharepoint Delegate Control

Question: What about codebehind-files? If this is allowed, where and how to deploy those?

Tanx

Thursday, December 28, 2006 4:08 AM by MSDNTST

# re: Use your ASP .NET WebControl in MOSS 2007 with Sharepoint Delegate Control

As I mentioned, with code behind files:

you need to copy the .cs or .vb file with the .ascx file

Tuesday, January 09, 2007 6:39 AM by Deepa

# re: Use your ASP .NET WebControl in MOSS 2007 with Sharepoint Delegate Control

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...

Friday, January 12, 2007 5:55 AM by Troels

# re: Use your ASP .NET WebControl in MOSS 2007 with Sharepoint Delegate Control

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)?

Monday, January 22, 2007 5:53 AM by Ravi

# re: Use your ASP .NET WebControl in MOSS 2007 with Sharepoint Delegate Control

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?

Wednesday, February 14, 2007 3:57 PM by Sriram

# re: Use your ASP .NET WebControl in MOSS 2007 with Sharepoint Delegate Control

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?

Thursday, March 08, 2007 6:00 AM by malvika

# re: Use your ASP .NET WebControl in MOSS 2007 with Sharepoint Delegate Control

The moment i install this "Stsadm -o installfeature -filename ASPNETControl\feature.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"

Monday, April 02, 2007 12:27 PM by Dregfdgf

# Good site

<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>

Tuesday, April 10, 2007 5:04 PM by uqaaw

# Poshol naxui

Tuesday, June 12, 2007 10:38 AM by Jonathan

# re: Use your ASP .NET WebControl in MOSS 2007 with Sharepoint Delegate Control

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.com

Friday, December 28, 2007 7:15 AM by Krutika

# re: Use your ASP .NET WebControl in MOSS 2007 with Sharepoint Delegate Control

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 ?

Sunday, March 02, 2008 2:42 AM by jesus libreros

# the delegate control is not render in the page

Hi, i had followed all steps . but the delegate control is not visible.

can you help me please, to resolve this trouble.

Sunday, March 02, 2008 5:54 PM by Vince

# re: Use your ASP .NET WebControl in MOSS 2007 with Sharepoint Delegate Control

Did you guys ensure the line :

<%@ Register tagprefix="SharePoint" namespace="Microsoft.SharePoint.WebControls" assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

was at the root of your .ASPX page ? Otherwise Sharepoint:Delegate is not know...

Wednesday, August 13, 2008 2:53 PM by mauricio

# re: Use your ASP .NET WebControl in MOSS 2007 with Sharepoint Delegate Control

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.

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker