Feeds:
Posts
Comments

Posts Tagged ‘control templatization’

Removing the default search box doesn’t seem so straight forward. This article explains how to remove (or replace) the search box or any other delegate control by using a feature.

Prerequisites:
- Know how to create a feature and have one ready.
- Know how to create an ascx control. (ASP.NET usercontrol)

Locating the searchbox.

The search box that you find on top of every page is defined in the default.master file. Go to your 12 hive and open the default.master in your favorite editor and you will find the following tag.

<SharePoint: DelegateControl ID="DelegateControl1" runat="server" ControlId="SmallSearchInputBox" />

To explain it fairly basically : ” You can replace delegates by some other control. So it gives you the possibility to load different controls into this location by activating feature(s) on your site. “.
This ‘switching’ between controls, is actually how SharePoint 2007 handles the difference in search between the WSS and the MOSS versions. When you have MOSS installed you have a more advanced search functionality than when you only have the free WSS version. Depending on the SharePoint version installed (actually what feature is activated), SharePoint replaces the searchbox with a more ‘advanced’ version.

Creating the feature.

Note: This part assumes that you already have a feature that you can modify.

To keep it simple we are going to replace the SmallSearchInputBox delegate by a usercontrol without any logic (code) behind it. To keep it simple our usercontrol only exists out of standard HTML.

  1. We will replace the searchbox with the text ‘ex-searchbox’. This to make it clear that it’s actually replaced. You can ofcourse remove the text or replace it by something else.
  2. Create a new text file and paste the following inside.
    <%@Control Language="C#" AutoEventWireup="true" %>
    ex-searchbox
  3. Save the file and rename the file to myEmptyControl.ascx
  4. Go to the ‘controltemplates’ folder ({12-hive}\TEMPLATE\CONTROLTEMPLATES).
  5. Create a new folder to put your custom usercontrols in. In my case the folder is ‘lawo’
  6. Copy your usercontrol into this folder.
    Note: Please use wsp solution files for proper deployments!!!
  7. Open the elements file of your feature.( this article assumes you know how to create one)
  8. In the elements.xml in the elements node of your feature you define the following line:
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
        <Control Id="SmallSearchInputBox" Sequence="24" ControlSrc="~/_controltemplates/lawo/myEmptyControl.ascx" />
    </Elements>
  9. Deploy the feature on your server.
  10. Do an iisreset.
  11. Activate your feature on the website.
  12. Go to the homepage of the site.
  13. The searchbox should be replaced by the text “ex-searchbox”.

Importance of SequenceId.

Notice that the sequenceId in step 6!
It defines what control has priority in case there are multiple features defined that ‘override’ the delegate control. If the SequenceId is too high the default SharePoint search controls might overrule yours.

I looked up the lowest sequence number used for this Delegate control by searching inside the files of the {12-hive}\TEMPLATE\FEATURES folder.  If you look in the folder of the ‘OSearchEnhancedFeature’  and open the file searcharea.xml. You will see that the SmallSearchInputBox is defined with a sequenceId 25. I took SequenceId 24 for my control (one lower) so it overrides the SearchBox in all the SharePoint versions.

Hope this helps. Feel free to leave comments.
–W

On the MSDN site you can find more information under “Control Templatization”.

Read Full Post »

Follow

Get every new post delivered to your Inbox.