How to change the HTML attributes of the HTML menu vb


I have a web page with master, two content pages and CSS , I would like to have the left side menu get class="current" when any of the pages appears

I tried every examples and all your answers like findcontrol and others but never work.

may be I have a problem cause I'm new to


CSS sheet

#templatemo_left_content {
  float: left;
  background: #0a2035 url("/images/templatemo_left_bg.jpg") top no-repeat;
  width: 358px;
  display: inline;

/* Menu */

.templatemo_menu {
  float: right;
  width: 211px;
  margin: 20px 65px 35px 0;
  padding: 0;
  display: inline;

.templatemo_menu ul {
  list-style-type: none;
  padding: 0;
  margin: 0;
  width: 211px;

.templatemo_menu li a {
  display: block;
  height: 27px;
  padding: 7px 0 0 50px;
  margin: 5px 0 0 0;
  color: #fff;
  font-weight: bold;
  background: url("/images/templatemo_menu.gif") no-repeat;

.templatemo_menu li a:hover, .templatemo_menu li .current {
  background: url(images/templatemo_menu_current.gif) no-repeat;
  color: #00FFFF;

/* End of Menu */

master page html

<div id="templatemo_left_content">
  <div class="templatemo_menu">
    <ul  style="height: 265px">
      <li id="Home" runat="server"  ><a href="Default.aspx" >Home</a></li>
      <li id="Products" runat="server" ><a href="#"  >Products</a></li>
      <li id="Services" runat="server" ><a href="#" >Services</a></li>
      <li id="About" runat="server" ><a href="About.aspx"  >About</a></li>
      <li id="Company" runat="server"><a href="#">About Our Company</a></li>
      <li id="Contact" runat="server" ><a href="#">Contact Us</a></li>
      <li id="Customers" runat="server"><a href="#l">Our Customers</a></li>

So, asked a question and discover the answer by yourself that is what happens

for you all thanks for reading and being involved

when you use it this way of creating Li

<li id="Home" runat="server"  ><a href="Default.aspx" >Home</a></li>

and uses the following code

Dim li As System.Web.UI.HtmlControls.HtmlGenericControl

     li = Page.Master.FindControl("Home")
     li.Attributes.Add("class", "current")

vb is calling home and it will change the the class but for a reason the menu background doesn't change cause it is located in tag a and not in tag Li so playing a little with the master html to adjust and place the id="Menu_Home" (can not use Home as the text has the same that is why I name it Menu_Home) inside tag a not in Li, also runat="server" will be shifted to to tag a as well it will be as following:

                    <div class="templatemo_menu">
                    <ul style="height: 235px">
                        <li><a href="Home.aspx" id="Menu_Home" runat="server"  >Home</a></li>
                        <li><a href="#" id="Menu_Products" runat="server" >Products</a></li>
                        <li><a href="#" id="Menu_Services" runat="server" >Services</a></li>
                        <li ><a href="#" id="Menu_Customers" runat="server">About Our Company</a></li>
                        <li><a href="About.aspx" id="Menu_About" runat="server"  >About</a></li>
                        <li ><a href="#" id="Menu_Contact" runat="server">Contact Us</a></li>

and in master load event add this code:

        Dim thisURL As String = Me.Page.[GetType]().Name.ToString()
    Select Case thisURL
        Case "home_aspx"
            Menu_Home.Attributes.Add("class", "current")
            Exit Select
        Case "about_aspx"
            Menu_About.Attributes.Add("class", "current")
            Exit Select
        Case "logout_aspx"
            Menu_Products.Attributes.Add("class", "current")
            Exit Select
    End Select

every thing is going to be fine