A A A Font Size

Kyle's SharePoint Karate

Design Minute: SharePoint Search Box

Design Minutes are quick design changes that you can make to your SharePoint site, adding flavor to the overall style of your design.

This Design Minute will focus on the SharePoint Search Box control.  Getting the search box to look just the way you'd like can be a frustrating task.  Fortunately, there are some quick and easy changes that you can make to the search control that can really add some style to your overall design.

The first step is customizing your master page.  The default.master uses a place holder (PlaceHolderSearchArea) to define the location in which your search box appears.  Unfortunately, a lot of the default page layouts will override the appearance of this place holder, and as a result, your search box can look different depending on what you're looking at.  This is a designer's worst nightmare -- you'll need to lock down the apperance of the search box before you can do anything else.

  1. Open your custom master page in SharePoint Designer
  2. Put this line of code at the top of your master page (it may already be there):
    <%@ Register Tagprefix="SPSWC" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
  3. Find the line in your master page that begins with <asp:ContentPlaceHolder id="PlaceHolderSearchArea"...
  4. You need this line of code in your master page, but we don't want it to appear, so put it in a hidden ASP panel near the bottom of your master page:
    <asp:Panel visible="false" runat="server"> <asp:ContentPlaceHolder id="PlaceHolderSearchArea" runat="server"/> </asp:Panel>
  5. Place the following code where you want your search box to appear:
    <div id="searchLayout"> <SPSWC:SearchBoxEx id="SearchBox" RegisterStyles="false" TextBeforeTextBox="" TextBoxWidth="200" GoImageUrl="" GoImageActiveUrl="" GoImageUrlRTL="" GoImageActiveUrlRTL="" UseSiteDefaults="true" DropDownMode="HideScopeDD" SuppressWebPartChrome="true" runat="server" WebPart="true" __WebPartId="{0043945F-2D2B-4A02-8510-CED13B6F04DF}"/> </div>

After saving your changes, you should see something like this on your site:

Initial Search Box Appearance

This isn't very exciting, I know, but it's a start.  Now that we have a static search box control (that won't change it's appearance!), we can start to add some style to it.  There are two images that I'm going to use for this search box -- a background image and a search icon.  Upload these two images somewhere on your server:

Search Icon    Search Background Image

With our images in place, all that's left is some CSS style additions.  Add the following two lines of code to your default CSS file:

#searchLayout input { background: transparent url('/images/search.gif') left no-repeat; padding-left: 25px; } #searchLayout .ms-sbcell { background: url('/images/searchBg.gif') repeat-x; border-color: #BD9BBD; }

Once you save your changes, your search box should look something like this:

Updated Search Box Appearance

That's it!  The CSS adds a magnifying glass to the input box, and it adds the repeating background image to the table cell that contains the input box.  If you'd like to show a javascript prompt string (such as "Search the Site"), just add QueryPromptString="Search the Site" to your search box control parameters.

You must sign in to rate content.
(Unrated)

Comments

Scope

I figured out the problem and was able to correct it. However, now, I want to specify a SPECIFIC scope to be used for this search. Is there an additional string I should add to make it search just a specific scope?

Thanks!
Tracey Nolte at 10/19/2009 5:57 PM
You must sign in to rate content.
(Unrated)

RE: Design Minute: SharePoint Search Box

Hi Kyle,

I've 2 questions in relation to your article:-

1. Whilst trying to copy your instructions I came across a part I wasn't able to achieve relating to the images.  I copied the images and uploaded them into an image library of my site.  When I accessed the CSS Stylesheet of the site (I think i got the correct one (from sharepoint designer _styles/core.css) I added in your two lines of CSS styling and changed the URLs to point to the images in my image library, but unfortunately to no avail.   Did I miss out on a step?

2. Similar to Tracey, is there a search box property to set the default scope, because I use a search centre using the method above (at least for me) isn't working as I'am only passing through the key word and exclusive of the search scope to the results page.

Thanks
Darren

Darren Kelly at 2/17/2011 11:51 AM
You must sign in to rate content.
(Unrated)

RE: Design Minute: SharePoint Search Box

Kyle -

Thanks so much! This gets me to a partial solution.

Do you have any advice for stacking the search scope drop down so that it sites above the search box? Looks like SP auto-wraps them in td tags and I've yet to figure out a solution.

AA
AA V at 2/25/2010 12:39 PM
You must sign in to rate content.
(Unrated)

How can remove the blue border and the background color of go image

Kyle, I am customizing a master page, and I don't know how to remove the default blue border for the search box and the background color for go image button. I found that I should change the css in core.css, but that would affect the search boxes in other pages which not created from the custom master page.
UU at 6/2/2008 1:38 PM
You must sign in to rate content.
(1 ratings)

RE: Design Minute: SharePoint Search Box

OK, thanks. Got it done. Next is to make more beautiful.
Aminuddin Johari at 7/20/2009 1:43 PM
You must sign in to rate content.
(Unrated)

RE: Design Minute: SharePoint Search Box

Hi, Kyle.. Thanks for the tips and i'd already tried it. It's working on the site page but not change in the main page eventhough I'm using same custom masterpage. Not sure why. Need your help..
Aminuddin Johari at 7/20/2009 1:45 AM
You must sign in to rate content.
(Unrated)

RE: Design Minute: SharePoint Search Box

One more thing, how to make a search button instead of hitting "enter" button.
Aminuddin Johari at 7/20/2009 1:48 PM
You must sign in to rate content.
(Unrated)

RE: Design Minute: SharePoint Search Box

Aminuddin, the search box can be tricky to style because a lot of SharePoint page layouts actually override the search box with a different (yet similar) ASP control.  In your master page, try moving the content place holder called "PlaceHolderSearchArea" into a hidden ASP panel (<asp:Panel visible="false" runat="server" />).

Leave your search control directly on your master page.  This way, the same search control will be displayed on every single page layout, regardless of any overrides to the SearchArea place holder.  I hope this helps!
Kyle Schaeffer at 7/20/2009 9:26 AM
You must sign in to rate content.
(1 ratings)

RE: Design Minute: SharePoint Search Box

I added the code exactly as you have stated in my masterpage. However, when I enter a search term and press enter, nothing happens, and I see the error code at the bottom left of the windows explorer screen that says "Error On Page". WHen I click to see the error, it says "documents.forms.elements[...] value is null or not an object"

Help?!?
Tracey Nolte at 9/21/2009 4:31 PM
You must sign in to rate content.
(Unrated)

Not working

I added the code exactly as you specified. However, when I press the enter key after typing in a search term, nothing happens. I see an error icon in the lower left corner. When I click the icon I see an error message that says " Error: 'document.forms.0.elements[...].value' is null or not an object.

I did register the component "<%@ Register Tagprefix="SPSWC"...."  and hide the original search with a panel near the bottom. I can't figure out why it's not working? Am I missing a component?
Tracey Nolte at 9/21/2009 4:44 PM
You must sign in to rate content.
(Unrated)

RE: Not working

Hi, Tracey.  It sounds like you might be missing/have too many FORM tags in your master page.  Right-click on the page in the browser, and select "View Source."  Search through the source and see how many "form" tags you can find.  If you don't see one, or if you have more than one, then you'll have to go back to your master page and correct that issue first.
Kyle Schaeffer at 9/21/2009 4:52 PM
You must sign in to rate content.
(Unrated)

RE: Design Minute: SharePoint Search Box

Kyle,
Your  article on "SharePoint Search Box" was a life saver....
I assumed customizing the search will take couple of days, but with you help.. completed in couple of hrs....
Thanks a lot...
Sincerely,
Priya
Priya Balapa at 9/3/2009 12:07 PM
You must sign in to rate content.
(Unrated)

RE: Design Minute: SharePoint Search Box

Kyle,
Your  article on "SharePoint Search Box" was a life saver....
I assumed customizing the search will take couple of days, but with you help.. completed in couple of hrs....
Thanks a lot...
Sincerely,
Priya
Priya Balapa at 9/3/2009 12:07 PM
You must sign in to rate content.
(Unrated)

RE: Not working

Hi, Tracey.  It sounds like you might be missing/have too many FORM tags in your master page.  Right-click on the page in the browser, and select "View Source."  Search through the source and see how many "form" tags you can find.  If you don't see one, or if you have more than one, then you'll have to go back to your master page and correct that issue first.
Kyle Schaeffer at 9/21/2009 4:52 PM
You must sign in to rate content.
(Unrated)

Not working

I added the code exactly as you specified. However, when I press the enter key after typing in a search term, nothing happens. I see an error icon in the lower left corner. When I click the icon I see an error message that says " Error: 'document.forms.0.elements[...].value' is null or not an object.

I did register the component "<%@ Register Tagprefix="SPSWC"...."  and hide the original search with a panel near the bottom. I can't figure out why it's not working? Am I missing a component?
Tracey Nolte at 9/21/2009 4:44 PM
You must sign in to rate content.
(Unrated)

RE: Design Minute: SharePoint Search Box

I added the code exactly as you have stated in my masterpage. However, when I enter a search term and press enter, nothing happens, and I see the error code at the bottom left of the windows explorer screen that says "Error On Page". WHen I click to see the error, it says "documents.forms.elements[...] value is null or not an object"

Help?!?
Tracey Nolte at 9/21/2009 4:31 PM
You must sign in to rate content.
(Unrated)

RE: Design Minute: SharePoint Search Box

Aminuddin, the search box can be tricky to style because a lot of SharePoint page layouts actually override the search box with a different (yet similar) ASP control.  In your master page, try moving the content place holder called "PlaceHolderSearchArea" into a hidden ASP panel (<asp:Panel visible="false" runat="server" />).

Leave your search control directly on your master page.  This way, the same search control will be displayed on every single page layout, regardless of any overrides to the SearchArea place holder.  I hope this helps!
Kyle Schaeffer at 7/20/2009 9:26 AM
You must sign in to rate content.
(1 ratings)

RE: Design Minute: SharePoint Search Box

One more thing, how to make a search button instead of hitting "enter" button.
Aminuddin Johari at 7/20/2009 1:48 PM
You must sign in to rate content.
(Unrated)

RE: Design Minute: SharePoint Search Box

Hi, Kyle.. Thanks for the tips and i'd already tried it. It's working on the site page but not change in the main page eventhough I'm using same custom masterpage. Not sure why. Need your help..
Aminuddin Johari at 7/20/2009 1:45 AM
You must sign in to rate content.
(Unrated)

RE: Design Minute: SharePoint Search Box

OK, thanks. Got it done. Next is to make more beautiful.
Aminuddin Johari at 7/20/2009 1:43 PM
You must sign in to rate content.
(Unrated)

How can remove the blue border and the background color of go image

Kyle, I am customizing a master page, and I don't know how to remove the default blue border for the search box and the background color for go image button. I found that I should change the css in core.css, but that would affect the search boxes in other pages which not created from the custom master page.
UU at 6/2/2008 1:38 PM
You must sign in to rate content.
(1 ratings)

RE: Design Minute: SharePoint Search Box

Kyle -

Thanks so much! This gets me to a partial solution.

Do you have any advice for stacking the search scope drop down so that it sites above the search box? Looks like SP auto-wraps them in td tags and I've yet to figure out a solution.

AA
AA V at 2/25/2010 12:39 PM
You must sign in to rate content.
(Unrated)

RE: Design Minute: SharePoint Search Box

Hi Kyle,

I've 2 questions in relation to your article:-

1. Whilst trying to copy your instructions I came across a part I wasn't able to achieve relating to the images.  I copied the images and uploaded them into an image library of my site.  When I accessed the CSS Stylesheet of the site (I think i got the correct one (from sharepoint designer _styles/core.css) I added in your two lines of CSS styling and changed the URLs to point to the images in my image library, but unfortunately to no avail.   Did I miss out on a step?

2. Similar to Tracey, is there a search box property to set the default scope, because I use a search centre using the method above (at least for me) isn't working as I'am only passing through the key word and exclusive of the search scope to the results page.

Thanks
Darren

Darren Kelly at 2/17/2011 11:51 AM
You must sign in to rate content.
(Unrated)

Scope

I figured out the problem and was able to correct it. However, now, I want to specify a SPECIFIC scope to be used for this search. Is there an additional string I should add to make it search just a specific scope?

Thanks!
Tracey Nolte at 10/19/2009 5:57 PM
You must sign in to rate content.
(Unrated)

How can remove the blue border and the background color of go image

Kyle, I am customizing a master page, and I don't know how to remove the default blue border for the search box and the background color for go image button. I found that I should change the css in core.css, but that would affect the search boxes in other pages which not created from the custom master page.
UU at 6/2/2008 1:38 PM
You must sign in to rate content.
(1 ratings)

RE: Design Minute: SharePoint Search Box

Aminuddin, the search box can be tricky to style because a lot of SharePoint page layouts actually override the search box with a different (yet similar) ASP control.  In your master page, try moving the content place holder called "PlaceHolderSearchArea" into a hidden ASP panel (<asp:Panel visible="false" runat="server" />).

Leave your search control directly on your master page.  This way, the same search control will be displayed on every single page layout, regardless of any overrides to the SearchArea place holder.  I hope this helps!
Kyle Schaeffer at 7/20/2009 9:26 AM
You must sign in to rate content.
(1 ratings)

RE: Design Minute: SharePoint Search Box

Hi, Kyle.. Thanks for the tips and i'd already tried it. It's working on the site page but not change in the main page eventhough I'm using same custom masterpage. Not sure why. Need your help..
Aminuddin Johari at 7/20/2009 1:45 AM
You must sign in to rate content.
(Unrated)

RE: Design Minute: SharePoint Search Box

OK, thanks. Got it done. Next is to make more beautiful.
Aminuddin Johari at 7/20/2009 1:43 PM
You must sign in to rate content.
(Unrated)

RE: Design Minute: SharePoint Search Box

One more thing, how to make a search button instead of hitting "enter" button.
Aminuddin Johari at 7/20/2009 1:48 PM
You must sign in to rate content.
(Unrated)

RE: Design Minute: SharePoint Search Box

Kyle,
Your  article on "SharePoint Search Box" was a life saver....
I assumed customizing the search will take couple of days, but with you help.. completed in couple of hrs....
Thanks a lot...
Sincerely,
Priya
Priya Balapa at 9/3/2009 12:07 PM
You must sign in to rate content.
(Unrated)

RE: Design Minute: SharePoint Search Box

I added the code exactly as you have stated in my masterpage. However, when I enter a search term and press enter, nothing happens, and I see the error code at the bottom left of the windows explorer screen that says "Error On Page". WHen I click to see the error, it says "documents.forms.elements[...] value is null or not an object"

Help?!?
Tracey Nolte at 9/21/2009 4:31 PM
You must sign in to rate content.
(Unrated)

Not working

I added the code exactly as you specified. However, when I press the enter key after typing in a search term, nothing happens. I see an error icon in the lower left corner. When I click the icon I see an error message that says " Error: 'document.forms.0.elements[...].value' is null or not an object.

I did register the component "<%@ Register Tagprefix="SPSWC"...."  and hide the original search with a panel near the bottom. I can't figure out why it's not working? Am I missing a component?
Tracey Nolte at 9/21/2009 4:44 PM
You must sign in to rate content.
(Unrated)

RE: Not working

Hi, Tracey.  It sounds like you might be missing/have too many FORM tags in your master page.  Right-click on the page in the browser, and select "View Source."  Search through the source and see how many "form" tags you can find.  If you don't see one, or if you have more than one, then you'll have to go back to your master page and correct that issue first.
Kyle Schaeffer at 9/21/2009 4:52 PM
You must sign in to rate content.
(Unrated)

Scope

I figured out the problem and was able to correct it. However, now, I want to specify a SPECIFIC scope to be used for this search. Is there an additional string I should add to make it search just a specific scope?

Thanks!
Tracey Nolte at 10/19/2009 5:57 PM
You must sign in to rate content.
(Unrated)

RE: Design Minute: SharePoint Search Box

Kyle -

Thanks so much! This gets me to a partial solution.

Do you have any advice for stacking the search scope drop down so that it sites above the search box? Looks like SP auto-wraps them in td tags and I've yet to figure out a solution.

AA
AA V at 2/25/2010 12:39 PM
You must sign in to rate content.
(Unrated)

RE: Design Minute: SharePoint Search Box

Hi Kyle,

I've 2 questions in relation to your article:-

1. Whilst trying to copy your instructions I came across a part I wasn't able to achieve relating to the images.  I copied the images and uploaded them into an image library of my site.  When I accessed the CSS Stylesheet of the site (I think i got the correct one (from sharepoint designer _styles/core.css) I added in your two lines of CSS styling and changed the URLs to point to the images in my image library, but unfortunately to no avail.   Did I miss out on a step?

2. Similar to Tracey, is there a search box property to set the default scope, because I use a search centre using the method above (at least for me) isn't working as I'am only passing through the key word and exclusive of the search scope to the results page.

Thanks
Darren

Darren Kelly at 2/17/2011 11:51 AM
You must sign in to rate content.
(Unrated)

Leave a Comment

You must be logged in to post a comment.
Superstar
Kyle Schaeffer
Sr. SharePoint UI Consultant
SusQtech
Williamsburg, VA

Search This Blog

 

© 2012 SusQtech. All rights reserved.
Powered by SharePoint Server 2007 and using the MemberToMember SharePoint Add-On for social media capabilities.