Welcome to MSDN Blogs Sign in | Join | Help

Project to customize the small search control in SharePoint 2007

The small search control that is rendered in the default SharePoint pages is a delegate control rendered through master page.  You can find it defined in the master page as follows: image

<asp:ContentPlaceHolder id="PlaceHolderSearchArea" runat="server">
    <SharePoint:DelegateControl runat="server" ControlId="SmallSearchInputBox" />
</asp:ContentPlaceHolder>

This control is actually available through a feature called "OSearchBasicFeature" located under 12\TEMPLATE\FEATURES.  In the feature elements file (in this feature it's called "SearchArea.xml"), you can see the following:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <Control 
        Id="SmallSearchInputBox" 
        Sequence="50"
        ControlClass="Microsoft.SharePoint.Portal.WebControls.SearchBoxEx" 
        ControlAssembly="Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">
    <Property Name="GoImageUrl">/_layouts/images/gosearch.gif</Property>
    <Property Name="GoImageUrlRTL">/_layouts/images/goRTL.gif</Property>
    <Property Name="GoImageActiveUrl">/_layouts/images/gosearch.gif</Property>
    <Property Name="GoImageActiveUrlRTL">/_layouts/images/goRTL.gif</Property>
    <Property Name="DropDownMode">ShowDD</Property>
        <Property Name="SearchResultPageURL">/_layouts/osssearchresults.aspx</Property>
    <Property Name="ScopeDisplayGroupName"></Property>
    <Property Name="FrameType">None</Property>
    </Control>    
</Elements>

The main class here seems to be Microsoft.SharePoint.Portal.WebControls.SearchBoxEx.  To customize small search, you need to inherit from "SearchBoxEx" class and override "CreateChildControls" method to get your custom small search rendered.  Do not modify any out of the box files as they might lead you into an unsupported scenario.  Instead, following are the simple steps to get the small search control customized:

  1. Create a custom master page by copying the default.master page.  I haven't tested with minimal master as explained here but I am guessing that would work either.
  2. Copy/Paste "OSearchBasicFeature" in the same feature folder with a different name (like mySimpleSearch).
  3. Change the feature ID in the feature.xml file within mySimplerSearch feature.
  4. Change the control ID in the SearchArea.xml file to something like "mySimleSearchcontrol".
  5. Change the class & assembly referenced in the SearchArea.xml file to the control library you created above.
  6. Install & Activate this feature,
  7. Render the custom control you created in the custom master page have and remove "SmallSearchInputBox" control from the master page.

This should do the tricky and you should be able to literally customizing anything within the small search control.

Happy customizing your SharePoint environment - and I really hope this post was helpful!  Look around for things like this in SharePoint as there are plenty of "hacks" to get things done!!!

Published Saturday, June 21, 2008 7:48 PM by sridhara

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Pregnant Man &raquo; Project to customize the small search control in SharePoint 2007

Tuesday, July 01, 2008 12:01 PM by bob e

# re: Project to customize the small search control in SharePoint 2007

A well written primer on this interesting topic.  Thanks you.

Tuesday, August 26, 2008 3:06 PM by Ted

# re: Project to customize the small search control in SharePoint 2007

Is it possible to provide some sample code here? I'm very interested in customizing the rendering of the small search control.

Tuesday, February 17, 2009 5:34 PM by Flannel

# re: Project to customize the small search control in SharePoint 2007

I desperately need to make the 2 search boxes stack on top of one another.  I really just need a little <br/> between them.

If you can show me this I'll send you $5 donation via Pay Pal.

Wednesday, April 01, 2009 8:31 AM by Sal Romano

# re: Project to customize the small search control in SharePoint 2007

Good stuff...

I will contribute another $15 to Flannel's $5 offer to bring the total to $20.  

Sridhar, can you show us how to stack the search boxes please?  

Wednesday, April 22, 2009 9:37 AM by oussar

# re: Project to customize the small search control in SharePoint 2007

I wont to do the DDL not visible. but to let the scope to All site by default because i use the facets serach.

how i can do this?

Thank u.

Aze

Friday, July 17, 2009 3:36 AM by amin

# re: Project to customize the small search control in SharePoint 2007

Hi Sridhar,

 I'd tried your method but i couldn't understand your step 5, on how to change the control and assembly.

Monday, August 10, 2009 1:19 PM by nareshveergaoni

# re: Project to customize the small search control in SharePoint 2007

Hi Sridhar, excellent post. can you please give us a detailed process involved in each step.. thanks a lot.

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker