is there a way to highlight the page you are on in the nav bar?

Topics: ASP.NET 2.0, Themes
Mar 11, 2011 at 3:27 AM

usually when i work on a site, if it has a nav bar and you click on one of the links in the nav bar, the link for that page will remain highlighted to indicate that's the page you are on. Normally i do this by adding a class value to the link, something like class="activelink"

And i normally do that by making whatever element that makes up the nav menu a .net control - i.e. runat="server" id="menuContact"

And then in my contact.aspx.cs page i'll have a bit of code like this:

        HtmlGenericControl myControl = (HtmlGenericControl)Master.FindControl("menuContact");
        myControl.Attributes.Add("class", "activeLink");

This doesn't work with blogengine. Is there anyother way to accomplish this?


Mar 11, 2011 at 5:05 PM

Take a look at the below theme.  It does what I believe you are asking for.

Mar 11, 2011 at 5:09 PM

From the site master
 <div id="nav-content"> <!-- <a href="javascript:void(filterByAPML())" class="apmlfilter"><%=Resources.labels.filterByApml %></a>--> <ul id="navigation"> <li <%=MenuClass("default.aspx")%>><a href="<%=Utils.AbsoluteWebRoot %>" rel="home"><%=Resources.labels.home%></a></li> <li <%=MenuClass("archive.aspx")%>><a href="<%=Utils.AbsoluteWebRoot %>archive.aspx"><%=Resources.labels.archive%></a></li> <li <%=MenuClass("contact.aspx")%>><a href="<%=Utils.AbsoluteWebRoot %>contact.aspx"><></a></li> <li <%=MenuClass("login.aspx")%>><a runat="server" id="aLogin" /></li> </ul> </div>

from the code behind

 public string MenuClass(string menuName)
      if (Request.RawUrl.Contains(menuName))
          return "class=\"current_page_item\"";
          return string.Empty;