Customising SharePoint Delegate Controls

I have been looking at customising the Sharepoint Search box on the fly.  You can do this 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…..

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 tag as part of another xml file in the feature
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 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.
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.


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