How to: Use the Search Box as a Web Control

The Search Box is a highly configurable Web Part, which, as any Web Part, can also be used as an HTML control. You can use each property of the Search Box Web Part as an attribute on the Search Box Web control. This topic demonstrates how to implement the Search Box as a Web control, and also lists the properties that you can configure to customize your search experience.

To add the Search Box Web control

  1. In the .aspx file for your Web page or Web form, add the appropriate register directive for the SPSWC control tag prefix.

    1. For released builds, use the following directive.

      <%@ Register Tagprefix="SPSWC" 
      Namespace="Microsoft.SharePoint.Portal.WebControls" 
      Assembly="Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
      
    2. For builds you are using for debugging, use the following directive.

      <%@ Register Tagprefix="SPSWC" 
      Namespace="Microsoft.SharePoint.Portal.WebControls" 
      Assembly="Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=94de0004b6e3fcc5" %> 
      
  2. In the same .aspx file for your Web page or Web form, add the Search Box control. The following simple example works in the same manner as the default Search Box on the Enterprise Search in Microsoft Office SharePoint Server 2007 search page.

    <SPSWC:SearchBoxEx id="SearchBox"  
    GoImageUrl="/_layouts/images/gosearch.gif" 
    GoImageUrlRTL="/_layouts/images/gosearch.gif" 
    DropdownModeEx=ShowDD 
    UseSiteDefaults="true" 
    FrameType="None" />
    

    The drop down list for this Search Box displays the contextual scope and the authored scope. The list shows by default the scope specified for the Search Dropdown display group. This example also uses the default "Go" image. See SearchBoxEx Properties (Microsoft.SharePoint.Portal.WebControls) for all of the properties and valid values that you can use when configuring your Search Box.

Example

The following example code shows how to customize the Search Box to display an Advanced Search link and customized display text that appears before the drop down list and the text input box. You must also include a value for AdvancedSearchPageURL so that The Advanced Search link can appear. This sample uses the register directive for released builds.

Customized search box control

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

<SPSWC:SearchBoxEx id="SearchBox"  
GoImageUrl="/_layouts/images/gosearch.gif" 
GoImageUrlRTL="/_layouts/images/gosearch.gif" 
DropdownModeEx=ShowDD 
TextBeforeDropDown = "Search"
TextBeforeTextBox = "For"
ShowAdvancedSearch = true
AdvancedSearchPageURL = "yourpage.aspx"
UseSiteDefaults="true" 
FrameType="None" />