Tuesday, December 04, 2007

Removing 'This Site' from the Search Control

I was recently asked to remove the 'This Site' scope from the Search scopes drop down in the header of my custom master pages, and as I wasn’t quite sure how or why it got there it sounded like it would provide a nice challenge for the afternoon.



Firstly the reason why they are there; this turned out to be due to the fact we were simply using the Search delegate control normally included on OOTB master pages/page layouts, which looks roughly along the lines of...

< asp:contentplaceholder id="PlaceHolderSearchArea" runat="server">
< sharepoint:delegatecontrol runat="server" controlid="SmallSearchInputBox">
< /sharepoint:delegatecontrol>
< /asp:contentplaceholder>

By default this control includes contextual scopes ('This Site'/'This List') as well as the custom scopes that you have defined for your site collection.

It looked a little light weight and puny so i swapped it out with the much bigger tougher looking;


< spswc:searchboxex id="SmallSearchBox" 
runat="server"
registerstyles="false"
textboxwidth="160"
usesitedefaults="true"
dropdownmode="ShowDD"
suppresswebpartchrome="true">
< /spswc:searchboxex>

The property that we need to look at here is the DropDownMode property, by setting its value to 'ShowDD_NoContextual' we successfully get rid of the 'This Site' contextual scopes.


Job done...



Or so I thought...


What I didn’t count on was my List view pages (AllItems.aspx) doing whatever the hell it pleases and ignoring the change I’d made to my master page. When I went to view the list I was given not only a ‘This Site’ contextual scope but for extra value a ‘This List’ contextual scope.




Some digging around lead me to discover that for some rather strange reason MS have made the ViewPage.aspx template (located at %12hive%\Template\Pages) explicitly overwrite the Search placeholder with the simple search control detailed at the beginning of this post. I’m baffled as to why given that the Form.aspx template located in the same place doesn’t do the overwrite!


As the majority of OOTB lists use this ViewPage.aspx to create its default AllItems.aspx it puts one in quite the little predicament.

I'd love to hear suggestions on how to get around this without simply modifying the OOTB ViewPage (naughty, naughty) or writing another JS hack. ;-)

1 comment:

Aravind said...

Hi Lee,
I read the article which defines a cool trick. In my case I'm missing a contextual scope "This List" in my farm. But "This Site" is Visible. I don't know how to make a workaround, if you have any idea regarding this, can you share with me.

Thanks,
Aravind