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

In 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 is under Office/SharePoint Visual C# templates. See fig below:

create delegate control sharepoint 2013

Here you can write the logic that 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 on 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 on the Manage Site Features page, you can deactivate the feature. The delegate control will not appear.

Custom Promoted Actions Delegate Control in SharePoint 2013

Now, let us see, how to implement PromotedActions Delegate Control in SharePoint 2013.

PromotedActions Delegate Control is responsible for displaying Links “Share, Follow, SYNC, EDIT” in the top right below SuiteLinksDelegate Control. These links can be replaced by Overriding PromotedActions Delegate Control using a Custom Control created using Visual Studio to the following area on a SharePoint site in the top-right section of the page.

Custom Promoted Actions Delegate Control in SharePoint 2013

Follow below steps to implement custom promoted actions delegate control in SharePoint 2013.

Step-1:
Create One Empty SharePoint Project and Provide the Solution Name and Choose the Solution Path and Click on OK.

Step-2:
Deploy the Solution as Farm Solution. Provide the Url in the next Screen and validate the Connection.

Step-3:
Add New UserControl to the Project from the Templates and Provide the Name to it, in our case it is “MyCustomPromotedActionsDelegate”.

promoted actions delegate control
promoted actions delegate control

Now Our Solution Explorer looks as follows:

promoted actions delegate control 2013
promoted actions delegate control 2013

Step-4:
Now open the “.ascx” of the User Control and paste the following code.

promoted actions delegate control sharepoint 2013
promoted actions delegate control sharepoint 2013

Step-5:
Add Elements.xml file to the Solution, Provide the name and click on Add.

sharepoint 2013 promoted actions delegate control
sharepoint 2013 promoted actions delegate control

Step-6:
Click on elements.xml file paste the below code snippet inside the element’s tag

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!– DelegateControl reference to the PromotedActions Delegate Control –>
<Control ControlSrc="/_controltemplates/15/PromotedActionsDelegate_Example/MyCustomPromotedActionsDelegate.ascx"
Id="PromotedActions"
Sequence="1" />
</Elements>

Step-7:
The final step is to build and deploy then adding an additional link.

The final Outcome will be look as follows:

create custom promoted actions delegate control sharepoint 2013
create custom promoted actions delegate control sharepoint 2013

SuiteBarBranding Delegate Control in SharePoint 2013/2016

This SharePoint 2013 tutorial explains, what is SuiteBarBranding Delegate Control in SharePoint? And how to implement custom SuiteBarBranding Delegate Control in SharePoint 2013/2016.

SuiteBarBranding Delegate Control in SharePoint

SuiteBarBrandingDelegate: This delegate care about top left site logo and text. Facilitates us to override the left-top corner text for the site. This text can only be replaced by Overriding SuiteBarBrandingDelegate Delegate Control with Custom Control Created using Visual Studio. Normally, there’s a text reading “SharePoint”. So we can replace it with the title of our own site:

Create SuiteBarBranding Delegate Control in SharePoint using Visual Studio

SuiteBarBrandingDelegate Control will look as follows in SharePoint Page.

Header before

sharepoint SuiteBarBranding Delegate Control
sharepoint SuiteBarBranding Delegate Control

Step-1:
Open visual studio and create One Empty SharePoint Project and Provide the Solution Name and Choose the Solution Path and Click on OK.

Step-2:
Deploy the Solution as Farm Solution. Provide the Url in the next Screen and validate the Connection.

Step-3:
Add New UserControl to the Project from the Templates and Provide the Name to it, In our case, it is “MyCustomSuiteBarBrandingDelegate”.

how to create custom SuiteBarBranding Delegate Control sharepoint 2013
how to create custom SuiteBarBranding Delegate Control sharepoint 2013

Now Our Solution Explorer looks as follows.

sharepoint SuiteBarBranding Delegate Control
sharepoint SuiteBarBranding Delegate Control

Step-4:
Now Open the “.ascx” of the User Control and paste the below code.

Custom SuiteBarBranding Delegate Control sharepoint 2016
Custom SuiteBarBranding Delegate Control sharepoint 2016

Step-5:
Code snippet for the ascx.cs file

Custom SuiteBarBranding Delegate Control sharepoint 2013
Custom SuiteBarBranding Delegate Control sharepoint 2013

Step-6:
Add Elements.xml file to the Solution, Provide the name and click on Add.

sharepoint 2013 SuiteBarBranding Delegate Control
sharepoint 2013 SuiteBarBranding Delegate Control

Step-7:
Click on elements.xml file paste the below code snippet inside the element’s tag

<?xml version="1.0″ encoding="utf-8″?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!– Adding DelegateControl reference to our custom SuiteBarBrandingDelegate Control –>
<Control ControlSrc="/_controltemplates/15/SuiteBarBrandingDelegate_Example\MyCustomSuiteBarBrandingDelegate.ascx"  Id="SuiteBarBrandingDelegate" Sequence="1″ />
</Elements>

Step-8:
The final step is to build and deploy and then the SharePoint text will be overridden with the Text of the portal.

The final Outcome will look as follows:

sharepoint 2016 SuiteBarBranding Delegate Control
sharepoint 2016 SuiteBarBranding Delegate Control

You may like following SharePoint tutorials:

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

    • Hi Paras,
      You have to migrate like you are migrating any solutions. Open the solution and change the .Net framework version if required, then create the wsp and then deploy the wsp.

  • >