Create custom delegate control in SharePoint 2013/2016 using Visual Studio

This SharePoint tutorial, we will discuss what is SharePoint delegate control? How to create a custom delegate control in SharePoint 2013/2016 using visual studio.

What is SharePoint Delegate Control?

Through SharePoint Delegate controls, you can inject code or control to a SharePoint master page without touching the code of the master page file.

This is how we can put a delegate control in the master page.

<SharePoint:DelegateControl runat="server" AllowMultipleControls="true" ControlId="ControlID"/>

Default SharePoint Delegate Controls in SharePoint 2013 and SharePoint 2010.

Below are a few examples of few Delegate controls in SharePoint 2013 and SharePoint 2010.

SharePoint 2013:

  • SuiteLinksDelegate
  • SuiteBarBrandingDelegate
  • PromotedActions

SharePoint 2010:

  • AdditionalPageHead
  • GlobalNavigation
  • GlobalSiteLink3
  • GlobalDelegate2
  • GlobalDelegate0
  • TopNavigationDataSource
  • SmallSearchInputBox
  • QuickLaunchDataSource

Create custom delegate control in SharePoint 2013/2016 using Visual Studio

Now, we will see how to create a custom delegate control in SharePoint 2013/2016 using visual studio.

Open visual studio and then File -> New Project, then select and Empty Project from the templates.

This it will ask to give your local SharePoint site URL for debugging. Here choose the farm solution option also.

sharepoint delegate control

We will add a Mapped folder into the project. Right-click on the project -> Add -> SharePoint Mapped Folder.. as shown below:

sharepoint 2016 delegate control

This will open the Add SharePoint Mapped Folder dialog box to select. There Select CONTROL TEMPLATES as shown in the fig below:

sharepoint 2013 delegate control

We will add one User Control inside the Control Templates folder. Right, click on the folder -> Add New Item and then select User Control (Farm Solution Only) which in under Office/SharePoint Visual C# templates. See fig below:

create delegate control sharepoint 2013

Here you can write the logic what you want to do inside the delegate control. I have just put a static message here.

Then our next step is to add an Empty Element to the project. For this Right-click on the project -> Add New Item Then Select Empty Element from the list of templates as shown in the fig below:

create delegate control sharepoint 2016

Now your solution and project should look like below as shown in the fig below:

create custom delegate control sharepoint 2013

Now open your Elements.xml file and add the code like below:

<Control Id="ControlToShowAlertMessage" Sequence="1" ControlSrc="/_controltemplates/15/ShowAlertMessage.ascx" />

Here Id is the one Id we are giving (we will use this while giving reference in master page). And then ControlSrc is the path of the user control which we have created earlier.

create custom delegate control sharepoint 2016

Now you can build and deploy the project. Once deployed successfully, you will be able to see under the Site Feature if you have deployed in Web scope else if you have deployed in the site scope then it will appear in the site collection feature.

Create delegate control in sharepoint

Now we can give the reference in the master page, Open your master page using SharePoint designer 2013. Then Check out and Edit in Advanced mode and then paste the below line in the master page.

<SharePoint:DelegateControl ControlId="ControlToShowAlertMessage" AllowMultipleControls="true" runat="server"></SharePoint:DelegateControl>

Here ControlId is the id which we have given in the Elements.xml file.

Then check in the master page and publish the page as a major version, then your delegate control will appear like below:

What is SharePoint Delegate Control?

Now let us say you do not need that to appear, then you can simply go to the Site Settings -> Manage Site Features. And then in the Manage Site Features page, you can deactivate the feature. The delegate control will not appear.

You may like following SharePoint tutorials:

This SharePoint tutorial, we learned what is SharePoint delegate control? How to create a delegate control using a visual studio in SharePoint 2013/2016.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>