Definition: Delegate Control is a custom functionality/control that can be placed in place of particular SharePoint functionality/control.
Some Points:
- We don’t need to change the existing functionality
- We don’t need to change the master page.
- We are creating our own functionality and replacing it with existing SharePoint functionality.
Delegate controls provided in SharePoint 2010:
- AdditionalPageHead: You can use this to inject scripts (JS, CSS, etc..) in the master page HTML Head Tags.
- GlobalNavigation: Top most control collection visible on page.
- GlobalSiteLink3: This delegate control is for two icons on the site. (1) I Like It (2) Tags & Notes
- GlobalDelegate2: SharePoint dashboard control
- GlobalDelegate0: You can change the top right section/menu. You can remove this space or add some more links to it.
- PublishingConsole: Server-side code for ribbon control is loaded using this delegate control. You can add you server actions in this control.
- TopNavigationDataSource: This control is for top navigation data source. You can use this control to change the default data source and load your own.
- SmallSearchInputBox: This control is for default small search box you see on the page.
- QuickLaunchDataSource: This control is for the data source of the left-hand side links panel. You can customize this to pass your own data source.
- TreeViewAndDataSource: This is different navigation other than quick launch and top navigation. You can pass your own data source here and render links accordingly.
Delegate controls provided in SharePoint 2013:
- SuiteLinksDelegate: Delegate control to handle links (1) Newsfeed (2) SkyDrive (3) Sites. You can add your own link also.
- SuiteBarBrandingDelegate: This control is for top left side site logo and text.
- PromotedActions: This control is for empty space between SHARE and FOLLOW link on top right corner
How to use:
- To create new Delegate Control, we need to create a package using Visual Studio
- Go to Visual Studio >> New SharePoint Project >> Farm solution.
- Create user control and place your content/code in this user control. OOB control will be replaced by the content of this user control.
- Now we need to register the control using Feature element.
- We need to specify the control to use, Sequence Number and URL to the control or assembly as described below, in Feature element file.
<?xml version=""1.0"" encoding=""utf-8"" ?>
<Elements xmlns=""http://schemas.microsoft.com/sharepoint/"">
<Control
Id=""SmallSearchInputBox""
ControlClass=""Namespace of the control class""
ControlAssembly=""Fully qualified assembly name""
Sequence=""100""
ControlSrc =""/templates/NewSearchcontrol.ascx""/>
</Elements>
Below are the parameters,
- Id=""SmallSearchInputBox"": This is Delegate Control name you want to replace with your control.
- ControlClass: (Optional) Namespace of the control class
- ControlAssembly: (Optional) Fully qualified assembly name
- Sequence=""100"": Type is Integer. Used for sequence number for the control. Control with the lowest sequence number is added to the tree.
- ControlSrc: Relative URL of the .ascx file, that is control file
- We are done. Now, Build >> Deploy and activate the feature.
- You will be able to see that OOB control is replaced by the custom control.