Share via


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="https://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!!!

Comments

  • Anonymous
    June 21, 2008
    PingBack from http://wordnew.acne-reveiw.info/?p=1351

  • Anonymous
    July 01, 2008
    A well written primer on this interesting topic.  Thanks you.

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

  • Anonymous
    February 17, 2009
    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.

  • Anonymous
    April 01, 2009
    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?  

  • Anonymous
    April 22, 2009
    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

  • Anonymous
    July 16, 2009
    Hi Sridhar,  I'd tried your method but i couldn't understand your step 5, on how to change the control and assembly.

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

  • Anonymous
    July 21, 2010
    Apparently, people are saying good post but all seems to be still confused.

  • Anonymous
    August 30, 2010
    I want to customize the small search control into two rows. I was searching a few hours through the web with no really helpful results. Can anybody help how i can dissolve the two rows problem?

  • Anonymous
    February 02, 2011
    Really nice artical, help me alot, May you be guided.