This article explains delegate control and also explains how to customize OOB small search box without more efforts.
Customizing OOB Small Search Input
Box
Here, I will
explain MOSS OOB SmallSearchInputBox control and then will explain how to
customize this box.
SharePoint
provides OOB search delegate control.
What is MOSS OOB SmakkSearchInputBox control?
SharePoint comes with the Out Of Box (OOB) control for the search the site content. This control renders on all the default pages of SharePoint using delegate control. This control is rendered using Default.master master page which is located at
C:\Program
Files\Common Files\Microsoft Shared\web server
extensions\12\TEMPLATE\GLOBAL (assuming C drive is the installation
drive for MOSS).
What is Delegate controls in
SharePoint?
1. Delegate
controls in SharePoint are used to add the controls (User control as well as
Server controls) on the SharePoint page, without any modification in SharePoint
page.
2.These
controls specify the features which control will be added.
For ex: Default master page includes the search box to
include the search box it uses the delegate control as
follows:
<SharePoint:DelegateControl runat="server"
ControlId="SmallSearchInputBox" />
Where ControlId : Control which is to be added
3. When
we add above code, it creates the instance of delegate control
4. Delegate
control uses Features to load the control specified in ConttolId attribute.
5. So for the SmallSearchInputBox control, when we install
SharePoint, two Features are installed
OSearchBasicFeature
and
OSearchEnahancedFeature.
For ex.
OSearchBasicFeature
is looks like as follows
<Feature Id="BC29E863-AE07-4674-BD83-2C6D0AA5623F"
Title="$Resources:BasicSearch_Feature_Title;"
Description="$Resources:BasicSearch_Feature_Description;"
DefaultResourceFile="spscore"
Version="12.0.0.0"
Scope="WebApplication"
ReceiverAssembly="Microsoft.Office.Server.Search, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
ReceiverClass="Microsoft.Office.Server.Search.Administration.BasicSearchFeatureReceiver"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="searcharea.xml"/>
</ElementManifests>
</Feature>
And searcharea.xml file looks like
<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>
6. So here if you at searcharea.xml, there
<Control> element is with the same Id which is specified in ControlId
attribute in delegate element in default.master page
7. Here one more important attribute is “
Sequence”. Value of sequence element
must be the lower than value of
Sequence element of the same control. This is
important to override existing delegate control. Because delegate
control
checks the list of controls from Features and if multiple controls found with
same ControlId then it
pickups the control with lowest sequence number.
8. So here conclusion is delegate control uses
Feature
to add the respective control on the sharepoint page and uses
Sequence
number to load the particular control if multiple same controls are
available.
Now back to our main point to
customizing the OOB smallsearchinput box, default OOB smallsearchinputbox having
the following elements:
1. Scope
Drop-Down
2. Text
Box for search keyword
3. Search
Button
4. Advanced
Search Link(in publishing sites)
and we have requirement is like
1. Hide the scope drop-down
2. Hide the Advanced Search Link
3. When we click on Go button, page should be redirected
to our custom search page
Now to
customize this OOB control, we will use following steps:
1. Copy
the OOB feature, rename it something like “CustomSmallSearchInputBox”
2. Change
the GUID of feature. (In VS, Tools >> Create GUID) also change the Title
and Description element.
3. We
will keep the values of Receiverassembly and ReceiverClass elements, since we
are overriding the OOB small
search input box.
4. Now
the
important changes in searcharea.xml file are:
a. Lower
Value of Sequence attribute of <Control> element so that OOB
search control will be overridden to ours one
b. Change
the properties values as per our requirement, For example:
i. To
hide the scope drop-down : -
<property Name="DropDownMode">
HideScopeDD </ Property>
ii. To
hide the advanced search link:-
<Property Name="ShowAdvancedSearch">false</Property>
iii. To
redirect search result at our custom page: - our custom page is Search.aspx in
Pages library
so the actual property becomes as
<Property
Name="SearchResultPageURL">/pages/search.aspx </Property>