Wednesday, October 9, 2013

How to Customise Default Search Input Box in SharePoint 2010


I’ve had the opportunity to have a request to change the Small Search Input Box. This is the small search box that is usually placed at the top right of a SharePoint page and says “Search this site…”. The requirement was to change the search scope from This Site to search the entire intranet. The result page that was going to be used was already made and worked perfectly. The last thing that was to be done was to change the text in the textbox from “Search this site…” to “Search…”.
The Small Search Input Box is a delegate control and is found in a master page as
1
<SharePoint:DelegateControl runat="server" ControlId="SmallSearchInputBox" />
This delegate control points to the control that is defined in the feature OSearchBasicFeature. This feature has the SearchArea.xml which contains the actual control definition as follows;
1
2
3
4
5
6
7
8
9
10
11
12
13
Id="SmallSearchInputBox"
Sequence="50"
ControlClass="Microsoft.SharePoint.Portal.WebControls.SearchBoxEx" ControlAssembly="Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">
    /_layouts/images/gosearch.gif
    /_layouts/images/goRTL.gif
    /_layouts/images/gosearch.gif
    /_layouts/images/goRTL.gif
    ShowDD
    /_layouts/osssearchresults.aspx
    
    None
The main things to notice here are the sequence number and the properties.
If you define another feature with a Control with the same Id as another delegate control uses, it is the control with the lowest Sequence value that will be used.
Secondly, the properties. If you look at the DropDownMode property it is by default ShowDD, which means the dropdown with the different scopes will be shown. The value can be changed to HideDD if the dropdown should not be visible.
So, to make the customizations to the Out of the box search box, let’s make a new feature and copy the Control tag from the SearchArea.xml to a new elements file. You have to make a new Element in Visual Studio 2010 to get the elements.xml. Then add the element to the feature using the designer. Then make the following changes;
1
2
3
4
5
Sequence = "40"
 
    <Property Name="DropDownMode">HideDD_useDefaultScope</Property>
    <Property Name="SearchResultPageURL">/search/pages/results.aspx</Property>
    <Property Name="QueryPromptString">Search…</Property>
One by one, the lines above will make the following changes:
1
Sequence = "40"
This will ensure that our feature control is used instead of the SharePoint standard.
1
<Property Name="DropDownMode">HideDD_useDefaultScope</Property>
This line will make the most important change that we want, to use the default scope and not showing the dropdown. This will make the default search toward another scope than the This Site scope. The default scope will have to be created later on.
1
<Property Name="SearchResultPageURL">/search/pages/results.aspx</Property>
This line will set the custom results page for the search. This aspx was already made and living happy in the environment. Perfect!
1
<Property Name="QueryPromptString">Search…</Property>
Set the text to be displayed before the user enters any text in the search box.
The only thing that has to be done now is to set a default scope for the Site Collection where the search is being deployed. To change the default scope navigate to _layouts/scopedisplaygroup.aspx?group=0 and make the changes.
Deploy the solution and test that the results are displayed from the correct scope.

No comments:

Post a Comment