Share via


How to: Customize a Delegate Control

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

This example shows the basic process of creating and implementing a delegate control candidate to use for the search box that is displayed on site pages. The control specifies alternate text and an alternate image file to use for the search box in Web sites where you activate the control.

To change the search box icon and alternate text

  1. Create a folder in the \Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES directory that is called NewSearchBox by copying the default \FEATURES\ContentLightup folder.

  2. In the NewSearchBox folder, open the copied Feature.xml file and generate a new GUID for the Feature by running guidgen.exe, which is located in Local_Drive:\Program Files\Microsoft Visual Studio 8\Common7\Tools. Set the Scope attribute to Web so that the Feature is activated at Web site level, as follows:

    <?xml version="1.0" encoding="utf-8"?>
    <Feature 
      Id="9E16894A-998F-4928-97B3-FCB35EAD1C49"
      Title="Standard User Interface Items"
      Description="Provides several standard user interface components and links"
      Version="12.0.0.0"
      Hidden="TRUE"
      DefaultResourceFile="core"
      Scope="Web"
      xmlns="http://schemas.microsoft.com/sharepoint/">
      <ElementManifests>
        <ElementManifest Location="controls\SearchArea.xml" />
      </ElementManifests>
    </Feature>
    
  3. In the Controls subfolder included in the first step, modify the SearchArea.xml file so that it references an alternate .ascx file. Also specify alternate text and a Sequence value that is lower than 100, such as the following:

    <?xml version="1.0" encoding="utf-8" ?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <Control 
        Id="SmallSearchInputBox" 
        Sequence="99"
        ControlSrc="~/_controltemplates/mySearchArea.ascx">
        <Property Name="SearchTextToolTip">Enter text here</Property>
        <Property Name="SearchImageToolTip">Go!</Property>
      </Control>
    </Elements>
    
  4. In \TEMPLATE\CONTROLTEMPLATES, copy the SearchArea.ascx file, and then rename this copied file mySearchArea.ascx.

  5. On the <img> tag that is located near the end of your copied .ascx file, modify the value of the src attribute to point to an alternate image file. For testing purposes, you can use one of the default image files installed in \TEMPLATE\IMAGES, such as in the following example, which replaces gosearch.gif with FOLDER.GIF.

    <INPUT Type=TEXT id='idSearchString' size=25 style='vertical-align: 2' name='SearchString' display='inline' maxlength=255 ACCESSKEY=S class='ms-searchbox' onKeyDown="return SearchKeyDown(event, <%=strEncodedUrl%>);" title=<%SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SearchTextToolTip),Response.Output);%>>
    <IMG SRC="/_layouts/images/blank.gif" width=4 height=1 alt="">
    <a target='_self' href='javascript:' onClick="javascript:SubmitSearchRedirect(<%=strEncodedUrl%>);javascript:return false;" title=<%SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SearchImageToolTip),Response.Output);%> ACCESSKEY=O ID=onetIDGoSearch>
        <img border='0' src="/_layouts/images/FOLDER.GIF" style='vertical-align: 1'alt=<%SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SearchImageToolTip),Response.Output);%>></a>
    &nbsp;
    </span>
    </nobr>
    
  6. At a command prompt, navigate to \Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN on the local drive, and type each of the following commands to install the Feature in the deployment, activate the Feature on a specified subsite, and reset Microsoft Internet Information Services (IIS) so that the changes take effect:

    stsadm -o installfeature -filename NewSearchBox\Feature.xml
    
    stsadm -o activatefeature -filename NewSearchBox\Feature.xml -url http://Server/Site/Subsite
    
    iisreset
    
  7. Navigate to the home page of the specified subsite to see the changes made to the search box.

See Also

Reference

DelegateControl

Concepts

Delegate Control (Control Templatization)

Delegate Controls