Hide SearchDropdown using DelegateControl

on Wednesday, March 3, 2010

Super Simple Feature for Hiding the Search Scope DropDown


So I need to hide the scope drop down that shows up next to the search box in my SharePoint MasterPage. 

Me:  "That's gotta be simple…  Just open up SharePoint designer and set some property on the search control." 


SharePoint: "Silly little boy!  Say hello to my little friend…err… DelegateControl!"

<Enter Jesse into world of SharePoint delegate controls>

Foolishness aside, the concept behind the DelegateControl is actually pretty useful, and because of it I was able to roll a very straightforward feature permitting me to hide the scope drop down in my MasterPage.  And I didn't even have to write one line of code… a true ode to developer sloth.


The feature….

   1: <?xml version="1.0" encoding="utf-8" ?>

   2: <!-- Copyright (c) Microsoft Corporation. All rights reserved. -->
   3: <Feature  Id="085B7E09-1D3E-41a7-9FEE-0C88F4394920"
   4:           Title="Custom Basic Search Control Feature"

   5:           Description="A feature for a search control that hides the Scope drop-down."
   6:           DefaultResourceFile="spscore"
   7:           Version="1.0.0.0"

   8:           Scope="WebApplication"
   9:           xmlns="http://schemas.microsoft.com/sharepoint/">
  10:     <ElementManifests>

  11:         <ElementManifest Location="searcharea.xml"/>
  12:     </ElementManifests>
  13: </Feature>

 

SearchArea.xml…

   1: <?xml version="1.0" encoding="utf-8" ?>

   2: <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   3:     <Control 
   4:         Id="CustomSmallSearchInputBox" 

   5:         Sequence="1"
   6:         ControlClass="Microsoft.SharePoint.Portal.WebControls.SearchBoxEx" ControlAssembly="Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">

   7:     <Property Name="GoImageUrl">/_layouts/images/gosearch.gif</Property>
   8:     <Property Name="GoImageUrlRTL">/_layouts/images/goRTL.gif</Property>

   9:     <Property Name="GoImageActiveUrl">/_layouts/images/gosearch.gif</Property>
  10:     <Property Name="GoImageActiveUrlRTL">/_layouts/images/goRTL.gif</Property>

  11:     <Property Name="DropDownMode">HideScopeDD</Property>
  12:     <Property Name="SearchResultPageURL">/_layouts/osssearchresults.aspx</Property>

  13:     <Property Name="ScopeDisplayGroupName"></Property>
  14:     <Property Name="FrameType">None</Property>

  15:     </Control>
  16: </Elements>

Two important things to note here… the Id of the control (CustomSmallSearchInputBox) and the DropDownMode (there are actually a bunch of different values you can set here).  So, install your feature, reference the CustomSmallSearchInputBox in your MasterPage and you're ret' to go:


   1: <asp:ContentPlaceHolder id="PlaceHolderSearchArea" runat="server">
   2:       <SharePoint:DelegateControl runat="server" ControlId="CustomSmallSearchInputBox"/>

   3: </asp:ContentPlaceHolder>

Theoretically speaking, you could roll your feature with the same ID as the SharePoint feature (SmallSearchInputBox), set the Sequence attribute to something super low, install your feature, and have your customized version start showing up throughout the site.  I myself prefer to keep my changes more modular.

0 comments: