Click here to Skip to main content
15,845,681 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
if I have this code in a user control file(ascx), I want the page current visited has class "active"
   <li class="active"><a href="a.html">Home</a></li>
   <li><a href="b.html">About Us</a></li>

for example: when I visited b.html, the html source should be:
<li ><a href="a.html">Home</a></li>
<li class="active"><a href="b.html">About Us</a></li>
Updated 5-Sep-14 22:34pm
JohnsonYuan 7-Sep-14 16:39pm    
in visual studio' menu control, it will auto add 'selected' css class to the current page
you can look this demo at

It's hard to do for user control, how can I do this in my project?

I think the better ways is to use pseudo code in CSS without changing the html source
 .active a:visited
  add css for visited
Share this answer
tha's not the point.

In order to set css class to
  • item, I have to this work like this:
    <% if(['some case']) { %>
        <li class="active">
    <% } else { %>
    <% } %>

    I think the key is how to determine the case to check whether to add css class.

    How can I know which page I'm loading now?

    It's not like news_list.aspx?id=14 that I can add css class by querystring,
    I have to page's like news_list.aspx, index.aspx...
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900