SharePoint Blogs / SharePoint University
SharePoint Blogs and SharePoint University - all in one place!
Need SharePoint Training? Attend a SharePoint Bootcamp!

Please delete cookies related to sharepointblogs.com and sharepointu.com to resolve login issues!

Using Delegate Controls in Sharepoint

After wrestling with the SDK information which skips a step or 2, I finally got the delegate control example to work that allows you to replace the Sharepoint Search box on the fly with your own custom control without ever having to touch the aspx page itself. This is a very cool feature with unlimited ramifications.

Why it is cool

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 every Sharepoint deployment I have ever done, it has been requested that the search box be modified, either comsmetically or functionally. In previous Sharepoint versions, this involvded either customizing the pages one by one and/or creating a whole new site defintion. WIth the concept of delegate controls in Sharepoint 2007, its a handful of lines of code and its far more powerful.

How it works

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

<SharePoint:DelegateControl 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 uses this same controlID but 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

 <Control
        Id="SmallSearchInputBox"
        Sequence="100"
        Controlsrc="~/_controltemplates/searcharea.ascx" mce_src="~/_controltemplates/searcharea.ascx">
    </Control>

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.

Caveats on the SDK Topic "How to: Customize a Delegate Control "

The SDK topic doesn't mention the sequence number being the key to which version of the control gets displayed (thanks guys), but if you run the new feature and change it to be lower or higher than 100, you will see the site act accordingly.

Also, do an IISreset each time before reinstalling the new feature or it wont work properly. At least it didnt for me.

Ramifications

Based on how you scope this feature, you can take any control, not just the search box and use the delegate control tag when creating a new site defintion or master page where your control may be located and easily customize the control's functionality or look and feel for any given collection or sub site as desired without changing anyone else's current implementation and without having to recode any pages.

This has a lot of use for branding and customizing of sites in a much more maintainable way than was previously possible.


Posted 05-24-2007 3:47 PM by Unclaimed Blog

Comments

Atlanta .NET Regular Guys wrote SharePoint Delegate Controls in SharePoint 2007 - Best Practices
on 12-14-2007 1:55 PM

SharePoint Delegate Controls: What EVERY SharePoint developer should know, but most do not. Every time

Shared Points... wrote Search features, web parts and delegate controls
on 04-15-2008 2:34 PM

SharePoint has got great power with it's delagate controls. With the default.master the following delegate

Microsoft news and tips » Search features, web parts and delegate controls wrote Microsoft news and tips &raquo; Search features, web parts and delegate controls
on 04-15-2008 2:51 PM

Pingback from  Microsoft news and tips &raquo; Search features, web parts and delegate controls

Skooter wrote re: Using Delegate Controls in Sharepoint
on 04-23-2008 3:54 AM

Is this MOSS only? 'cause i cannot find the xml-file that contailns the sequence-thing in WSS 3.

porno wrote re: Using Delegate Controls in Sharepoint
on 06-07-2008 3:58 PM

thanx docs

ss wrote re: Using Delegate Controls in Sharepoint
on 01-14-2009 2:14 AM

not useful at all.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Need SharePoint Training? Attend a SharePoint Bootcamp!
Posts (c) their respective authors. Everything else (c) 2009 SharePoint Experts, Inc.