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.
SharePoint 2016 Tutorial Contents
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"/>
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.
We will add a Mapped folder into the project. Right-click on the project -> Add -> SharePoint Mapped Folder.. as shown below:
This will open the Add SharePoint Mapped Folder dialog box to select. There Select CONTROL TEMPLATES as shown in the fig below:
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:
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:
Now your solution and project should look like below as shown in the fig below:
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.
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.
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:
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:
- Implement Custom Promoted Actions Delegate Control in SharePoint 2013
- New Delegate Control additions to the SharePoint 2013
- How to Implement Custom SuiteBarBranding Delegate Control in SharePoint 2013/2016
- Implement Custom SuiteLinks Delegate Control in SharePoint 2013
- Create a Custom Action Group using Visual Studio 2015 for SharePoint 2016
- SharePoint 2016 Develop and deploy custom feature using Visual Studio 2015
- Create list instance and list definition in SharePoint 2016 using visual studio
- Create a web part page using visual studio 2013 in SharePoint 2013
- Create and deploy site pages or content pages using a visual studio in SharePoint 2013/2016
- How to create site definition using Visual Studio 2013 in SharePoint 2013
- Create List Definition and List Instance in SharePoint 2013/2016 using Visual Studio 2013/2015/2016
This SharePoint tutorial, we learned what is SharePoint delegate control? How to create a delegate control using a visual studio in SharePoint 2013/2016.
I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SPGuides.com
Download SharePoint Online Tutorial PDF FREE!
Get update on Webinars, video tutorials, training courses etc.