I’m still learning asp.net and wanted to know if there was a simple way to set the id=”current” to the navigation bar so that depending on the page a user was on it would highlight that page. My template is set up to use the id=”current” to change the style of the link and I have i class to set the style of each tab.
Here is the code in my Site.Master
<nav id="navigation" class="style-1">
<div class="left-corner"></div>
<div class="right-corner"></div>
<ul class="menu" id="responsive">
<li><a href="home.aspx" id="current"><i class="home"></i> Home</a></li>
<li><a href="Calendar.aspx"><i class="calendar"></i>Calendar</a></li>
<li><a href="Bill.aspx"><i class="list"></i>Bills</a></li>
</ul>
</nav>
Like I said, I’m still learning so i’m not sure if it would be better to place it in a ContentPlaceHolder. I tried to just request the URL and do if statements but I wasn’t sure how to set the id=.
Any help would be great.
Thanks
You should look into setting the
classof your menu items rather than theidin order to display it as highlighted.You can do something as so.
Add an
idandrunat="server"to each of your links:Then in the code-behind of your master page, you can set the classes to each as they’re navigated to:
This will set the class of link that matches your current page to
current. Of course you will need to define that class in your style sheet. But this should work.