Add Custom Search box 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. 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

<Feature Id=”541F5F57-C847-4e16-B59A-B31340E6F9E4A”
Title=”My Custom Search Box”
Description=”Replaces Out-of-Box search box with my Custom Search box.”
ReceiverAssembly=” OurCustomSearchControl, Version=, 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″ ?>
<Elements xmlns=””>
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

<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.

Relate Post on other blog: Custom Search WebPart for Sharepoint 2010


  1. Thomas Balkeståhl says:

    This is an excellent post, I will have great use for it.
    I have one request that would make it complete though, could you please add a description on how to add code from the existing searchbox or add a sample so that it is easier to get started?
    The line ‘and write your logic for custom search box.’ is what I’m stuck at currently.
    Thomas Balkeståhl – Technical Specialist – SharePoint

  2. You can also use the _spUserId variable that is available in all sharepoint pages derived from v4.master and most other master pages. This will give you the current user’s id if that is enough for you (can be used to save into list for e.g. if you pass “_spUserId;#” to the list, it will automatically find the user and save it.)

    To get current users’s name without a server call, you can use the text inside the Welcome control. For e.g. “Welcome, FirstName LastName”, you can parse and pick this text. This too works fine.

Speak Your Mind


Disclaimer: The contents of this site are provided “AS IS”. Information and views expressed including URL(s) and other Internet website references, may change without notice. You bear the risk of using it. SharePoint, MOSS, SharePoint 2010, SharePoint 2013 and Microsoft are trademarks of the Microsoft Corporation.Learning SharePoint only provides Tips,Tricks and Tutorials for using Microsoft SharePoint, Microsoft Office and related Softwares.
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.