Page view counter

Referencing Master Page - Tab like <li><a href

Last post 09-28-2006 10:37 AM by Paul44. 2 replies.

Sort Posts:

  • Referencing Master Page - Tab like <li><a href

    09-11-2006, 3:52 PM
    • Loading...
    • Paul44
    • Joined on 05-13-2006, 11:58 AM
    • Posts 50
    • Points 131

    I am trying to modify the Commerce Starter Kit using C#.  The Commerce Starter Kit comes with a Master Page that comtains controls as follows:

    ======================================================================================================== 

    <><%@ Master Language="C#" AutoEventWireup="true" CodeFile="site.master.cs" Inherits="site" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <link id="Link1" rel="stylesheet" type="text/css" href='js/modal/subModal.css' runat="server" />
        <meta name="description" content="Description here" />
        <meta name="keywords" content="Keywords here"  />
        <title></title>
     </head>
    <body>
    <script src="<%=Page.ResolveUrl("~/js/effects/prototype.js") %>" type="text/javascript"></script>
    <script src="<%=Page.ResolveUrl("~/js/effects/scriptaculous.js") %>" type="text/javascript"></script>
    <form id="elForm" runat="server">
        <div id="header">
            <div id="logo">
                <a href="<%=Page.ResolveUrl("~/default.aspx")%>"><img src="<%=Page.ResolveUrl("~/images/csklogo.gif")%>" alt="Your Logo Here"/></a>
            </div>
            <div id="menu1">     
                <asp:LoginView ID="LoginView1" runat="server">
                    <AnonymousTemplate>
                        <ul>
                            <li class="first"><a href="<%=Page.ResolveUrl("~/basket.aspx")%>"><img src="<%=Page.ResolveUrl("~/images/icons/cart.gif")%>"  align="absmiddle" alt=""/> My Cart <%if(ShowBasket()){%>(<%=this.GetItemCount()%>)<%} %></a></li>
                            <li><a href="<%=Page.ResolveUrl("~/login.aspx") %>">Log In</a></li>
                            <li><a href="<%=Page.ResolveUrl("~/login.aspx") %>">Register</a></li>
                        </ul>               
                    </AnonymousTemplate>
                    <LoggedInTemplate>
                    <ul>
                        <li class="first">Welcome Back <%=Page.User.Identity.Name %>!</li>
                        <li><a href="<%=Page.ResolveUrl("~/basket.aspx")%>"><img src="<%=Page.ResolveUrl("~/images/icons/cart.gif")%>"
                                                  align="absmiddle" alt=""/> My Cart <%if (ShowBasket())
                                                  {%>(<%=this.GetItemCount()%>)<%} %></a></li>
                        <li><a href="<%=Page.ResolveUrl("~/myorders.aspx")%>">My Orders</a></li>
                        <li><asp:LinkButton ID="lnkLogout" CausesValidation="false" runat="server" Text="Log out" OnClick="lnkLogout_Click"></asp:LinkButton></li>
                    </ul>            
                    </LoggedInTemplate>          
                </asp:LoginView>
            </div>
            <div id="mainmenu">
                <ul>
      <li>
                    <li><a href="<%=Page.ResolveUrl("~/default.aspx")%>" id="tab_Home" class="selected">Home</a></li>
                    <li><a href="http://forums.asp.net/AddPost.aspx?ForumID=139#" id="tab_Services">Services</a></li>
                    <li><a href="http://forums.asp.net/AddPost.aspx?ForumID=139#" id="tab_Contact">Contact</a></li>
                    <li><a href="<%=Page.ResolveUrl("~/About.aspx")%>" id="tab_About">About</a></li>
                    <li><a href="<%=Page.ResolveUrl("~/AboutSelected.aspx")%>" id="tab_AboutSelected" class="selected">AboutSelected</a></li>
                    <%if(Page.User.IsInRole("Administrator")){ %>
                    <li><a href="<%=Page.ResolveUrl("~/admin") %>" id="tab_Admin">Admin</a></li>
                    <%} %>
                </ul>
            </div>
        </div>
        <div id="bar">
            <div id="searchbar">
                Search:
                <input type="text" name="txtSearch" /><a href="http://forums.asp.net/AddPost.aspx?ForumID=139#" onclick="location.href='<%=Page.ResolveUrl("~/search.aspx")%>?q='+document.forms[0].txtSearch.value">
                <asp:Image ID="btnSearch" runat="server" SkinID="doSearch" ImageAlign="AbsMiddle" /></a>
            </div>
        </div>
        <asp:contentplaceholder  id="ContentPlaceHolder1" runat="server">
        </asp:contentplaceholder>
        <!--#INCLUDE File=includes/modal_divs.aspx-->
    </form>
    </body>
    </html>
    <script type="text/javascript">
    function popItScroll(theLink){
        window.open(theLink,null,'height=800,width=700,scrollbars=yes,resizable=yes');
    }
    function showIt(theBox){
        if(theBox.style.display==""){
            theBox.style.display="none";
        }else{
            theBox.style.display="";
        }
    }
    function toggleIt(theBox){
        if(theBox.style.display=="none"){
            new Effect.Appear(theBox);
        }else{
            new Effect.Fade(theBox);
        }
    }
    </script>

    <>========================================================================================================

    The <li> 's in the <div id = mainmenu>  now contain a   <li><a href= ~~~~~~~ id="tab_Home"   that I added.

    I can find examples that show how to change the Text for a Label control on a Master Page -but- I can't find how to address the  class  atribute from the Master Page for a href.....  When the About tab is clicked in the PageLoad of the About page I am trying to set the  class="selected" of the tab_Home to  class = ""   and then set the  class="selected" for the tab_About.  All that I am trying to do is to shift the Highlight from the tab_Home tab to the tab_About tab.....  This seems to me to be a simple thing that everyone using tabs would want to do ?

    I guess that the real question is:

    I have found examples like        ((Label)Master.FindControl("Label1")).Text = TextBox1.Text;

    -but- this is a Label - - - how can I do a FindControl for a     <li><a href     ???

    Can someone please help on this issue ?

    Thanks in advance,

    Paul

     

  • Re: Referencing Master Page - Tab like <li><a href

    09-28-2006, 9:24 AM
    • Loading...
    • stemyers
    • Joined on 09-28-2006, 1:11 PM
    • Leeds, West Yorkshire
    • Posts 1
    • Points 5

     Hiya,

     Your li's and href's are not server controls, you can only reference server controls in the c# code.

     You have 2 choices, you can either turn your a link tags into server controls by adding the runat="server" attribute and obtaining a reference to the control as follows:

     HtmlAnchor tab_Home = MasterDetail.FindControl("tab_Home") as HtmlAnchor;
     Or you can replace the link tags with <asp:HyperLink> server controls as follows

    <asp:HyperLink NavigateUrl="<%=Page.ResolveUrl("~/About.aspx")%>" ID="tab_About" runat="server">About</asp:HyperLink>

     and reference these controls in the c# code as: 

    HyperLink tab_Home = MasterDetail.FindControl("tab_Home") as HyperLink;
     Hope this answers your question

     Stephen

     
  • Re: Referencing Master Page - Tab like <li><a href

    09-28-2006, 10:37 AM
    • Loading...
    • Paul44
    • Joined on 05-13-2006, 11:58 AM
    • Posts 50
    • Points 131

    NOW - this is what I call an answer (examples and all) - Thank you Stephen...

    I had found that if I defined the links as HyperLink(s) like:

     <asp:HyperLink ID="HyperLink_Home" CssClass="selected" Text="Home" NavigateURL = "~/default.aspx" runat="server"></asp:HyperLink>

    Then I could reference them like:

    HyperLink hyperHome = (HyperLink).Master.FindControl("HyperLink_Home");

    if (hyperHome != null)

    {

        hyperHome.CssClass="";

    }

    I don't really like this hard codeed approach -but- :)  It works...

    We should probably set up some kind of loop that would look through the Tabs and un-select 'all' of them - then set the 'current' Tab to selected.  That would be a lot cleaner for a generic Kit.

    Thanks again Stephen,

    Paul

     

Page 1 of 1 (3 items)