Wednesday 1 June 2011

Delegate Control

The Delegate Controls comes into picture when want to brand a SharePoint Site. The delegate control acts like a container control which encapsulates default content (set of child controls inside it). The default content (set of child controls associated with delegate) can be substituted by a specific control, by creating a feature. The ability to override or substitute the delegate controls brings the power & flexibility to brand SharePoint Sites.

The out-of-box SharePoint Foundation Master Page defines many controls like Top Navigation Data Source, Left Navigation Data Source, Search Box and Additional Page Head etc as delegate controls. The list is illustrated below :-
<SharePoint:DelegateControl runat="server" ControlId="AdditionalPageHead" AllowMultipleControls="true"/>
<SharePoint:DelegateControl runat="server" ControlId="GlobalNavigation" />
<SharePoint:DelegateControl runat="server" ID="GlobalDelegate0" ControlId="GlobalSiteLink0" />
<SharePoint:DelegateControl ControlId="GlobalSiteLink2" ID="GlobalDelegate2" Scope="Farm" runat="server" />
<SharePoint:DelegateControl runat="server" ControlId="PublishingConsole" Id="PublishingConsoleDelegate" />
<SharePoint:DelegateControl ControlId="GlobalSiteLink3" Scope="Farm" runat="server" />
<SharePoint:DelegateControl runat="server" ControlId="SmallSearchInputBox" Version="4" />
<SharePoint:DelegateControl runat="server" ControlId="TopNavigationDataSource" Id="topNavigationDelegate"/>
The above listed delegate controls can be substituted at runtime to achieve custom branding. Or else we can create our own delegate and we can add to our master page.
<SharePoint:DelegateControl ControlId="TimeZoneDelegate" runat="server"/>

Steps to create DelegateControl:
  1. File -> New Project -> SharePoint Empty Project.
  2. Add New Class and change its base class to System.Web.UI.WebControls.WebControl
  3. Override required methods like OnLoad,CreateChildControls or Render.
  4. Add New Module with Elements.xml and add the below tag. add the safe control entry as well.
    <Control Id="TimeZoneDelegate"  Sequence="100" ControlClass="addedclassFullName" ControlAssembly="$SharePoint.Project.AssemblyFullName$"  ></Control>
  5. Instead of adding a class we can use an UserControl and refer it in ControlSrc property of Control tag in place of ControlClass and ControlAssembly.
  6. Deploy the feature.

No comments:

Post a Comment