Monday, November 11, 2013

Replace SharePoint 2010 out-of-the-box Search box with custom control

When you create a SharePoint site using any templates, it will create a search box at the top right of the page and says ‘Search this site…’. There may be some situations you can’t go with out-of-the-box search box. This article will explain how to replace the OOTB search box with a custom control.

Create a SharePoint custom web part to replace the search box and include all your custom logics.

At the Elements.xml file of the web part include the following section.
xml version="1.0" encoding="utf-8"?>
<Elements xmlns="" >
<Control      Id="SmallSearchInputBox"
Sequence="23"         ControlClass="Search.WebParts.SearchAutoSuggestionTextBoxWebPart.SearchAutoSuggestionTextBoxWebPart"

This will register your control through feature elements. You must specify the following properties;

Id: Give an Id for the custom control. The Id name of the search control is ‘SmallSearchInputBox’ (as specified in the master page).
Sequence: Define a lowest sequence number. If you define another control with same Id and with a lowest sequence number, the lowest value will be used.
ControlClass: Specify the code behind class file (fully qualified name) of the control.

You have created the search box. Next step is to replace the OOTB search box at the master page. You need to modify the master page to complete this.

Find the DelegateControl used for the search box.
<SharePoint:DelegateControl ID="DelegateControl1"
ControlId="SmallSearchInputBox" />
If you have specified a different name for the control, you need to give the correct Control Id instead.

Deploy the feature and check; the OOTB search box is replaced.

No comments:

Post a Comment