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. Because of its lower sequence number than the already existing control, the corresponding Delegate control (which loads the Out-of-box control) will pick up your custom control.
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
Title=”My Custom Search Box”
Description=”Replaces Out-of-Box search box with my Custom Search box.”
ReceiverAssembly=” OurCustomSearchControl, Version=220.127.116.11, Culture=neutral, PublicKeyToken=71e9bce111e9429c”
<ElementManifest Location=” elements.xml”/>
. 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″ ?>
Sequence=”10″ -> Remember to give it a lower number than the existing SmallSearchInputBox control
ControlAssembly=” OurCustomSearchControl Assembly”/>
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
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.
Relate Post on other blog: Custom Search WebPart for Sharepoint 2010