The best practise, when you want to add a Webpart into a MasterPage is using a Delegate Control with a Feature. I wanted to add a Content Query Webpart into my Masterpage Page headline with a Custom Delegate Control. Note! You can not add a Webpart Zone into a MasterPage just static Webparts! Many of the controls used on default.master are loaded using the Delegate Control. These include global links such as My Site/My Links and the publishing console. So using this approach, customizing the publishing console is a simple matter of providing a replacement .ascx and creating a feature as described here!
Why using a Delegate Control?
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. 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.
On every Sharepoint deployment I have ever done, it has been requested that the search box be modified, either comsmetically or functionally.
Here is a short example:
<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
<!– using a sequence number LOWER than default of 100 so our custom control gets loaded –>
<Control
Id=”SmallSearchInputBox”
Sequence=”61″
Controlsrc=”~/_controltemplates/searcharea.ascx” mce_src=”~/_controltemplates/searcharea.ascx”>
</Control>
Only thing to note here at this stage is the ControlId attribute – the Feature we create will use this to substitute the real user/server control.
Read the rest of this entry »