hi, i m trying to create a site in Asp.net using C#... I just added a master page and here i put the menu like: <div id="menu"> <!-- HINT: Set the class of any menu link below to "active" to make it appear active --> <ul> <li><a href="#" class ="active">Home</a></li> <li><a href="addemp.aspx">Add Employee</a></li> <li><a href="#">Emp Details</a></li> <li><a href="#">Generate PaySlip</a></li> <li><a href="#">Attandance</a></li> </ul> </div> Here as you see the home link have a class active... here i have the problem in changing the sataus of this class while navigating through the site.... thanks, Rohan
you could use javascript: <script type="text/javascript"> window.onload = function() { var mnuLinks = document.getElementById("menu").getElementsByTagName("a"); for (i=0;i<mnuLinks.length;i++) { if(window.location.href.toLowerCase().search(mnuLinks[i].href.toLowerCase()) > -1) mnuLinks[i].className = "active"; } } </script> Code (markup): It isn't perfect but should do the job. It just checks all the hrefs from the links in the menu and see's if they are contained within the document location, if they are it sets the class of that link to 'active'.
As camjohnson95 said u can use his script to achive your requirement. Alternatively you can try using the ASP.Net Menu control and set the selected item styles. Using ASP.Net Menu control gives you more flexibilty as you don't have to hard code the Menu links into your application.
Good Idea... I have used the menu control once before and it is okay. It allows you to do basic menus (without having to do any js coding), and you can use images and/or text etc. But I could not remember if you could change the style of the active link. Probably a better option than the javascript and another handy feature of asp.net. A bit of a tip, the sitemap that you must create for the menu control, is not compatible with Google Webmasters...