Feature for adding Custom SmallSearchInputBox in sharepoint 2010

Adding your own Custom controls like search box or quicklaunch bar and replacing the existing ones, is infact a pretty easy task in SharePoint 2010. All you need to do is to create and install a feature that specifies your own custom control and give a lower sequence number for in your elements.xml file.

Lets see the steps for replacing the Out-of-Box search box with the Custom Search Box control
1. Create a empty project in VS 2010.
2. Add a web user control (ascx file) in your project and write your logic for the custom search box. You can very well use the code behind files along with your ascx control, but don’t forget to change the ascx file’s Inherit tag to Inherit from the complied (and signed) .dll of the project.
3. Create a Feature -

. Add a new xml file to your project and name it as Fetaure.xml file . The content of the file will be something like below
<Feature Id=”541F5F57-C847-4e16-B59A-B31340E6F9E4A”
Title=”My Custom Search Box”
Description=”Replaces Out-of-Box search box with my Custom Search box.”
Version=”1.0.0.0″
Scope=”Web”
ReceiverAssembly=” OurCustomSearchControl, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”
ReceiverClass=”OurCustomSearchControl.SearchControl”
xmlns=”http://schemas.microsoft.com/sharepoint/”>
<ElementManifests>
<ElementManifest Location=” elements.xml”/>
</ElementManifests>
</Feature>
. Add another file in your project called elements.xml. Here we will use tag to specify our own custom search control box. The contents of the elements.xml file will be something like below :
<?xml version=”1.0″ encoding=”utf-8″ ?>
<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”>
<Control
Id=”SmallSearchInputBox”
Sequence=”10″ -> Remember to give it a lower number than the existing SmallSearchInputBox control
ControlClass=”OurCustomSearchControl”
ControlAssembly=” OurCustomSearchControl Assembly”/>
</Elements>
4. Sign in and deploy.
Now, what happens behind the scenes?
Microsoft SharePoint Foundation implements a mechanism to declare candidate or out-of-box controls for a particular functionality by using a DelegateControl. he DelegateControl is embedded inside SharePoint Foundation pages and acts based on this information. So, in our case i.e. for the search box we should have DelegateControl in our master page something like below
<SharePoint:DelegateControl ControlId=”SmallSearchInputBox”/>
At run time, this control accepts the union of control elements declared at the server farm, Web application, site collection, and Web site levels. The control that has the lowest sequence number is added to the control tree by means of the DelegateControl. In the case of a sequence tie, the order of controls is arbitrary.

0 comments:

Post a Comment

Disclaimer

This is a personal weblog. The opinions expressed here represent my own and not those of my employer or anyone else. Should you have any questions or concerns please e-mail me at sharepointprogrammingblogger@gmail.com .

Copyright (c) 2010 @ myshaepointwork.blogspot.com. All rights are reserved.Do Not Copy.

@ Learning SharePoint.com