Here I talk about how to modify a new master page to include the contextual search redirect box (covered in my earlier post: Part 1).

I thought it might be a good idea to display the contextual search box in left navigation bar, my reasoning being that a contextual search is like the other quick launch items in being "site specific" - but hey; it's really up to you.

Modify the layout of your search box

In order to display the search box correctly in the left navigation / quick launch area, we are going to have to modify the layout and sizes of the selection and input boxes.

  • Replace the table code in your newsearcharea.ascx file (everything from and including <table to </table> with the following code:

    <table border=0 cellpadding="0" cellspacing="0" width="100%"><tr>
    <td>
    <SELECT id='idSearchScope' name='SearchScope2' style='width:100%' title=<%SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SearchScopeToolTip),Response.Output);%>>
    <OPTION value=<%=strScopeWeb%> <%=strWebSelected%>> <SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,search_Scope_Site%>" EncodeMethod='HtmlEncode' Id='idSearchScopeSite'/> </OPTION>
    <%
    if (strScopeList != null)
    {
    %>
     <OPTION value=<%=strScopeList%> SELECTED> <SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,search_Scope_List%>" EncodeMethod='HtmlEncode' Id='idSearchScopeList'/> </OPTION>
    <%
    }
    %>
    </SELECT>
    </td>
    </tr>

    <tr>
    <td width=100%>
    <INPUT style='width:100%' Type=TEXT id='idSearchString' size=15 name='SearchString' display='inline' maxlength=255 ACCESSKEY=S class='ms-searchbox2' onKeyDown="return SearchKeyDown(event, <%=strEncodedUrl%>);" title=<%SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SearchTextToolTip),Response.Output);%>>
    </td>
    </tr>
    <tr><td>
    <a target='_self' href='BLOCKED SCRIPT' onClick="BLOCKED SCRIPTSubmitSearchRedirect(<%=strEncodedUrl%>);BLOCKED SCRIPTreturn false;" title=<%SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SearchImageToolTip),Response.Output);%> ID=onetIDGoSearch><img border='0' src="/_layouts/images/gosearch.gif" alt=<%SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(SearchImageToolTip),Response.Output);%>></a>
    </td></tr></table>

Note: Obviously it is good to have a little HTML / JAVA and XML knowledge, this is not what this post is about, so use and modify the above code to your hearts content.

Include the contextual search box control in your master page

In my example I am using a copy of the stock standard default.master page which can either be found in the 12\Template\Global directory or in the Master Pages and Layouts gallery of your site collection.

  • Make a copy of the default.master and lets call it contextual.master.
  • Open the contextual.master in your favorte editor (I like notepad A LOT).
  • To add the contextual search box control to just below the standard quicklaunch bar (and style it to look like the quicklaunch) copy and paste the following code just before the following tags: </asp:ContentPlaceHolder><asp:ContentPlaceHolder id="PlaceHolderLeftActions" runat="server">:

    <!-- BEGIN CONTEXTUAL SEARCH -->
    <div class="ms-quicklaunchouter">
        <div class="ms-quickLaunch" style="width:100%">
    <div class="ms-quicklaunchheader"><SharePoint:SPLinkButton id="SearchHeading" runat="server" NavigateUrl="~site/_layouts/viewlsts.aspx" Text="Site Search" AccessKey=""/></div>
    <asp:ContentPlaceHolder id="PlaceHolderSearchAreaCustom" runat="server">
         <SharePoint:DelegateControl runat="server" ControlId="ContextualSearchRedirect" />
        </asp:ContentPlaceHolder>
    </div>
    </div>
    <!-- END CONTEXTUAL SEARCH -->
  • Note the text highlighted in bold:
    • PlaceHolderSearchAreaCustom: I copied the default search area placeholder and gave it a unique name
    • ContextualSearchRedirect: The unique Control ID for the custom search control explained in the previous post.
  • Now upload your master page, approve and publish and then apply to your relevant site.

Regards,

Doug (bobTheBuilder) McCusker