How to: Customize a Delegate Control
Published: May 2010
To build the delegate control
Start SharePoint development tools in Microsoft Visual Studio 2010.
On the File menu, point to New, and then click Project.
In Project Types, under Visual Basic or C#, select Empty SharePoint Project.
Type EcmaScriptDelegate as the project name. Click OK.
In the SharePoint Customization Wizard, choose Deploy as a farm solution. Click Finish.
In the Solution Explorer, right-click the EcmaScriptDelegate project. Select Add and then New Item.
In the Add New Item dialog box, click the Code group and choose the Class template. Type EcmaScriptDelegateControl as the Name and then click Add.
Next, you must add a reference to System.Web. In the Solution Explorer, right-click the References folder and select Add Reference. In the Add Reference dialog, click the .NET tab and find System.Web in the list. Click OK.
In the EcmaScriptDelegateControl file that is displayed, add the following using statement.
Change the base class of EcmaScriptDelegateControl to WebControl by modifying the following line.
Override the OnLoad method by adding the following code.
Now, you have built the delegate control for the project. Next, you will create the Feature to deploy the control.
To create a Feature to deploy the control
In the Solution Explorer, right-click the EcmaScriptDelegate project and select Add and then New Item.
In the Add New Item dialog box, choose the Empty Element template and type EcmaScriptDelegateFeature as the Name. Click Add.
Insert the following XML inside the Elements element. The Id attribute identifies the delegate where the control is rendered. The ControlAssembly and ControlClass attributes are unique to your control. For more information about how to find the full assembly name, see How to: Create a Tool to Get the Full Name of an Assembly.
You now have both the control and the Feature you need to deploy the control. Controls require a SafeControl entry in the web.config file in order to run on the page. The following procedure adds a SafeControl entry for your control.
To add a SafeControl entry
In the Solution Explorer, click EcmaScriptDelegateFeature and click ... in the Safe Control Entries property.
Click Add in the Safe Control Entries dialog.
In the Properties box, ensure that the Namespace property is the correct value. This is the namespace of your control. Also, ensure that the Safe property is set to true. Click OK.
Now that the SafeControl entry is added, you can deploy the solution.
To deploy and test the delegate control
Press F5 to run the solution.
When the page loads, a dialog box appears that says Hello, world!. This is the script that the delegate control has added to the page.