Need help with a menu bar in BlogEngine

Last post 05-05-2009 3:26 AM by ajitsatpathy. 6 replies.

Sort Posts:

  • Need help with a menu bar in BlogEngine

    09-20-2008, 10:57 AM
    • Member
      77 point Member
    • QWERTYtech
    • Member since 06-17-2007, 2:32 AM
    • Wichita Falls, TX
    • Posts 362

    I have the follwoing code snippet: 

    <div id="menu">

    <ul>

    <li class="active"><a href="<%=Utils.AbsoluteWebRoot %>" accesskey="1" title="">Home</a></li>

    <li><a href="<%=Utils.AbsoluteWebRoot %>archive.aspx" accesskey="2" title="">Archive</a></li>

    <li><a href="<%=Utils.AbsoluteWebRoot %>aboutus.aspx" accesskey="4" title="">About Us</a></li>

    <li><a href="<%=Utils.AbsoluteWebRoot %>contact.aspx" accesskey="5" title="">Contact</a></li>

    <li><a href="<%=Utils.FeedUrl %>" accesskey="3" title=""><img src="<%=Utils.AbsoluteWebRoot %>pics/rssButton.gif" alt="Feed" />Subscribe</a></li>

    </ul>

    </div>

     

    On my 3rd line of code, i have a class of active. I want to code all of my links that if they are licked, they are active. The active turns on a background around them to show that it is the current active tab.

     

    Can anyone please help me with this??????

    QWERTYtech
    QWERTYtech
  • Re: Need help with a menu bar in BlogEngine

    09-21-2008, 1:40 AM
    • Participant
      1,278 point Participant
    • vijayakrishna
    • Member since 02-18-2006, 7:23 PM
    • Pune, India
    • Posts 225

     Give an IDs to the li tags and make them as server controls in the following way

    <li id="liHome" runat="server"><a href="<%=Utils.AbsoluteWebRoot %>" accesskey="1" title="">Home</a></li>

    Now add the class attribute dynamically to li tag of your interest in the code behind file in the following way

    liHome.Attributes.Add("class","Active");

    Vijaya Krishna Paruchuri
    Please remember to click “Mark as Answer” on the post that helped you. This credits that member, earns you a point and marks your thread as resolved.
  • Re: Need help with a menu bar in BlogEngine

    09-21-2008, 1:56 AM
    • Member
      77 point Member
    • QWERTYtech
    • Member since 06-17-2007, 2:32 AM
    • Wichita Falls, TX
    • Posts 362

    Sorry, but I'm still a little confused on what I'm suppost to do.

    QWERTYtech
    QWERTYtech
  • Re: Need help with a menu bar in BlogEngine

    09-21-2008, 4:03 AM
    • Participant
      1,278 point Participant
    • vijayakrishna
    • Member since 02-18-2006, 7:23 PM
    • Pune, India
    • Posts 225

    Change your code as shown below. 

    <div id="menu">

       <ul>

          <li id="liHome" runat="server"><a href="<%=Utils.AbsoluteWebRoot %>" accesskey="1" title="">Home</a></li>

          <li id="liArchive" runat="server"><a href="<%=Utils.AbsoluteWebRoot %>archive.aspx" accesskey="2" title="">Archive</a></li>

          <li id="liAboutUs" runat="server"><a href="<%=Utils.AbsoluteWebRoot %>aboutus.aspx" accesskey="4" title="">About Us</a></li>

          <li id="liContact" runat="server"><a href="<%=Utils.AbsoluteWebRoot %>contact.aspx" accesskey="5" title="">Contact</a></li>

          <li id="liSubscribe" runat="server"><a href="<%=Utils.FeedUrl %>" accesskey="3" title=""><img src="<%=Utils.AbsoluteWebRoot %>pics/rssButton.gif" alt="Feed" />Subscribe</a></li>

       </ul>

    </div>

    Now on the respective .aspx.cs files you add the class attribute dynamically to the related li.

    For Eg. On the home page Page_Load it could be

    liHome.Attributes.Add("class","Active");

    On the archive.aspx Page_Load it could be

    liArchive.Attributes.Add("class","Active")

    and so on for the other pages too.

    Vijaya Krishna Paruchuri
    Please remember to click “Mark as Answer” on the post that helped you. This credits that member, earns you a point and marks your thread as resolved.
  • Re: Need help with a menu bar in BlogEngine

    09-21-2008, 10:40 AM
    • Member
      77 point Member
    • QWERTYtech
    • Member since 06-17-2007, 2:32 AM
    • Wichita Falls, TX
    • Posts 362

    Does it matter that I'm using a MasterPage??

    QWERTYtech
    QWERTYtech
  • Re: Need help with a menu bar in BlogEngine

    09-21-2008, 1:34 PM
    Answer
    • Participant
      1,278 point Participant
    • vijayakrishna
    • Member since 02-18-2006, 7:23 PM
    • Pune, India
    • Posts 225

    If you are uisng it on the master page,  then in the maser page.cs file in the Page_Load you can have something like the following to detect the called page and you can add the attribute as per the page. 

    if (Request.Url.ToString().ToLower().IndexOf("archive.aspx") > 0)
    {
    lstArchive.Attributes.Add("class", "Active");
    }
    
    Vijaya Krishna Paruchuri
    Please remember to click “Mark as Answer” on the post that helped you. This credits that member, earns you a point and marks your thread as resolved.
  • Re: Need help with a menu bar in BlogEngine

    05-05-2009, 3:26 AM
    • Member
      190 point Member
    • ajitsatpathy
    • Member since 06-12-2008, 2:46 AM
    • New Delhi
    • Posts 61

    I don't think that, there you should change in your code. Keep your code as it is.

    You want to use a class "active" when it is active. Just define a css named as " #menu li a:active" and write the same css which you have written in "active" class. it'll be work fine.

    Ajita Kumar Satpathy
    Filed under:
Page 1 of 1 (7 items)