SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using a Master Page - Display a Search Box on all pages

    I'm using a master page to add a search box to the navigation bar on all my pages, but I also have a dedicated search page that has it's own search box. I would like the navigation search box to show up on every page except the dedicated search page. What's the best way to accomplish this?


    I'm presently including the navigation search box like so:

    HTML Code:
    <form id="Form1" runat="server">
    
          (other page stuff)
    
    	    <div id="menu">
    		    
    
                           (Other menu Stuff)		
    		    
    	            <asp:Panel ID="sSearchBox" runat="server" DefaultButton="sButton" CssClass="searchBox">
                            <asp:Label ID="sLabel" runat="server" Text="Label" CssClass="sLabel">Search</asp:Label>
                            <asp:TextBox ID="sText" CssClass="sText" runat="server" ></asp:TextBox>
                            <asp:Button ID="sButton" runat="server"  EnableTheming="True" ToolTip="Search" 
                            PostBackUrl="~/search.aspx" CssClass="sButton" />
    	            </asp:Panel>
    		    
    	    </div> <!-- End Menu -->
    </form>

  2. #2
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    In the master page you would have something like this:
    Code ASP.NET:
    	<form id="Form1" runat="server">
     
          (other page stuff)
     
    	    <div id="menu">
     
     
                           (Other menu Stuff)		
    <asp:contentplaceholder id="SearchBoxLayout" runat="server">		    
    	            <asp:Panel ID="sSearchBox" runat="server" DefaultButton="sButton" CssClass="searchBox">
                            <asp:Label ID="sLabel" runat="server" Text="Label" CssClass="sLabel">Search</asp:Label>
                            <asp:TextBox ID="sText" CssClass="sText" runat="server" ></asp:TextBox>
                            <asp:Button ID="sButton" runat="server"  EnableTheming="True" ToolTip="Search" 
                            PostBackUrl="~/search.aspx" CssClass="sButton" />
    	            </asp:Panel></asp:contentplaceholder>
     
    	    </div> <!-- End Menu -->
    </form>

    On normal pages you'll just leave <asp:Content ID="MenuLayout" ContentPlaceHolderID="SearchBoxLayout" runat="server"> out but on the dedicated search page replace it with:
    Code ASP.NET:
    <asp:contentplaceholder id="SearchBoxLayout" runat="server"/>

    Alternately, you could put
    Code Csharp:
    Panel x = (Panel)Master.FindControl("sSearchBox");
    x.Visible = false;
    in the Page_Load(object sender, EventArgs e) of search.aspx.cs

  3. #3
    SitePoint Wizard webcosmo's Avatar
    Join Date
    Oct 2007
    Location
    Boston, MA
    Posts
    1,480
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Kitty got a better way.
    Here is another way of doing it.
    on master page code behind check the page name, if its search page hide the search on nav.

    if(Request.Url.ToString().ToLower().IndexOf("/search.aspx")>0) //considering page name is search.aspx
    {
    //make search part invisible.
    }

  4. #4
    Non-Member
    Join Date
    Nov 2010
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I checked the requirement you only need to show navigation search box on every page except the dedicated search page for this in dedicated search page you just need to find the id of searchtextbox on page load event of the dedicated search page and set visible false.

    Like i have used for label control like

    lblM = (Label)Master.FindControl("lblMP");
    lblM.Visible = false;

  5. #5
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SynapseIndia View Post
    I checked the requirement you only need to show navigation search box on every page except the dedicated search page for this in dedicated search page you just need to find the id of searchtextbox on page load event of the dedicated search page and set visible false.
    Well, that leaves the panel control in place. Taking my suggestion above prevents the entire panel from rendering.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •