Customize Search Box


Ever wanted to make the Search Box in SharePoint a little less, um, boring?

Well then I have some good news, you can make it pretty cool with a few minutes of time for both configuration and branding.

First things first, you have to make a small addition to your default master page. Open the master page in SharePoint Designer and add the following entry at the top:

<%@ Register TagPrefix="SPSWC" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

After that’s done, don’t leave your master page just yet, do a Ctrl+F and search for “PlaceHolderSearchArea” to find the current search box. You’re going to want to take the following chunk of code and place it into a hidden ASP panel:

<asp:ContentPlaceHolder id="PlaceHolderSearchArea" runat="server"/>

Note: Don’t forget that last “/”, or you will get errors when saving the master page.

Here’s how the chunk of code should look once it’s in the hidden panel, note that I placed mine right above the closing BODY and HTML tags.

<!--HIDDEN SEARCH INPUT-->
<asp:Panel visible="false" runat="server">
<asp:ContentPlaceHolder id="PlaceHolderSearchArea" runat="server"/>
</asp:Panel>
<!--HIDDEN SEARCH INPUT-->

(I add comments to everything so I can always re-trace my steps)

Once that’s done, you should have a hidden search box if you view the Design mode screen. Now is the time to add the new search box. Here’s the chunk of code required for that action:

<!--ADD SEARCH HERE-->
<div id="searchLayout">
<SPSWC:SearchBoxEx id="SearchBox" RegisterStyles="false" QueryPromptString="Search This Site" TextBeforeTextBox="" TextBoxWidth="200" GoImageUrl="" GoImageActiveUrl="" GoImageUrlRTL="" GoImageActiveUrlRTL="" UseSiteDefaults="true" DropDownMode="HideScopeDD" SuppressWebPartChrome="true" runat="server" WebPart="true" __WebPartId="{0043945F-2D2B-4A02-8510-CED13B6F04DF}"/>
</div>

You may notice I have “Search This Site” under the QueryPromptString tag; this is so I can see “Search This Site” in my search box once my search box customization is complete. You can put anything you want here, or if you prefer a blank box, leave it blank.

Once I save my master page, I now have a pretty blank (border only) search box with “Search This Site” inside. Now is the time to brand it a little with some CSS…

In my custom style sheet, I added the following to make mine pretty:

#searchLayout input {
background:transparent;
background-image:url("magGlass.png"); 
background-repeat:no-repeat; 
padding-left:20px;
}
td.ms-sbcell{
background-position:0px -100px;
padding:0px;
padding-left:5px;
white-space:nowrap;
border:solid 1px #990099;
}

Note: I made a little magnifying glass image to put inside the box. Mine is called magGlass.png, and I set the padding to 20px to push the text to the right of my magnifying glass image. Here’s the finished product:

Leave a comment