Delegate Control – What & How

Using the concept of a delegate control, you can take any control that exists in Sharepoint today or your own custom creations and place them on a sharepoint page such that they override the existing control at whatever scope you desire (individual site, site collection or farm) and yet require no recoding of the page(s) itself.

On a typical WSS page, there is no longer
a Search Box control tag, just this little beauty…..

runat=”server”  ControlId=”SmallSearchInputBox“/>

The delegate control tag, the best I can deduce, does a lookup of the features on the site that will share the controlID value of “SmallSearchInputBox“. Out of the box, there is only 1 of these declared, in the feature called ContentLightup.

What you can do (as documented in the SDK) is create your own feature that (1) uses this same controlID but (2) refers to a different underlyling .ascx (custom control) file. The delegate control feature will then check the list of all controls with this same ID and use the one that has the lowest sequence number
as declared in the <control> tag as part of another xml file in the feature

        Controlsrc=”~/_controltemplates/searcharea.ascx” mce_src=”~/_controltemplates/searcharea.ascx”>

Thus by copying the original feature and lowering the sequence number and changing the Controlsrc attribute to point to your .ascx file, you will cause Sharepoint to dynamically change the control that <SharePoint:DelegateControl> tag produces on the page.

A delegate control is user control that has a predefine space on a page that can be changed by turn on or off a feature.  The stock example used is, if you want to change the search area you could upload a feature with a user control to replace it with your own.  Delegate controls are based on numbered sequences with the lowest being displayed.  Yours just has to be the lowest.

Rule of Thumb –

  1. When designing your page, create delegate controls for functionality that might change over time. (i.e. the search box like Microsoft did)
  2. Don’t over use delegate controls. You will find once you understand them you will want to use them everywhere.
  3. Number 3 is my most important rule, you should have 3 delegate controls on every page.
  4. Don’t put too many delegate controls in a single feature, remember they all deploy together. (light up/turn off together)
  5. Keep good track of the sequence and don’t put the number too low.  You don’t want to have trouble overriding the feature in the future.

A Delete Contron would look like this, on a Sharepoint Page.



(If AllowMutiple=”true”
then the Delete Control can load more than one usr controls)

In VS 2010, the Elements.xml


<!– using a sequence number LOWER than default of 100 so our custom control gets loaded –>

ControlSrc=~/_ControlTemplates/COBPageHeader.ascx />





Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: