Click here to Skip to main content
15,905,028 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"
XML
<ul>
   <li class="active"><a href="a.html">Home</a></li>
   <li><a href="b.html">About Us</a></li>
</ul>

for example: when I visited b.html, the html source should be:
<ul>
<li ><a href="a.html">Home</a></li>
<li class="active"><a href="b.html">About Us</a></li>
</ul>
Posted
Updated 5-Sep-14 21:34pm
v2
Comments
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 http://aspnet451.planetwrox.com/PhotoAlbums/

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
ex:
CSS
<style>
 .active a:visited
{
  add css for visited
}
</style>
 
Share this answer
 
v2
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 { %>
        <li>
    <% } %>


    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
 
v2

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