Today I am going to explain about creating delegate controls in sharepoint.
If you want to see any delegate controls you can visit in the master page. For publishing site there is nightandday.master page which is default master page for the home page of the site.
You can find the following delegate controls in the nightandday.master page.
<SharePoint:DelegateControl runat="server" ControlId="AdditionalPageHead" AllowMultipleControls="true"/> <SharePoint:DelegateControl ControlId="GlobalSiteLink3-mini" Scope="Farm" runat="server"/>
Before moving to how to create a delegate control, first we look at what is the importance of delegate control.
Mapping the delegate control to master page
After creating the delegate control now we want to add it to the master page. To do this we have one tag that is
<SharePoint:DelegateControl runat="server" ControlId="" AllowMultipleControls=""/>
ControlId –> is the Id of the control which we given in the elements.xml file while deploying the file. (Don’t worry at this time. We will cover in how to create delegate control in Visual Studio section)
This is the main element for delegate control.
Creating delegate control in Visual Studio
Now I am creating a small control to enable a link for registering the new user in home page.
To do this, you have to enable the forms based authentication. If you are not familiar to how to setup forms based authentication for sharepoint 2010 site then visit previous post.
<div id="RegisterUserDiv" runat="server"> <a href="#">Sample Delegate Control</a> </div>
<?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <Control Id="RegisterHereControl" Sequence="1000" ControlSrc="~/_controltemplates/RegisterUser.ascx" /> </Elements>
<SharePoint:DelegateControl ControlId="RegisterHereControl" AllowMultipleControls="true" runat="server"></SharePoint:DelegateControl>