I have a menu list in my master page and in each page on my web site I want the current page to be highlighted in the menu.
Here is the relevant snippet of the MasterPage file:
I tried using this code, but it gives an error "Object reference not set to an instance of an object".
I tried the same code, just to test if I could add a class attribute to the BODY tag and that worked ok.
So why doesn't it work for the LI tag? Is it because it's a sub-item of something else?
Here is the relevant snippet of the MasterPage file:
HTML:
<body id="master_body" runat="server">
<div id="header">
<div class="container">
<div id="top-menu">
<ul class="menu">
<li> <a href="default.aspx" title="" id="menu-item-home"> <span> Welcome </span> Home </a> </li>
<li> <a href="about.aspx" title="" id="menu-item-about"> <span> Who we are </span> About </a>
I tried using this code, but it gives an error "Object reference not set to an instance of an object".
HTML:
Dim myControl As HtmlGenericControl = CType(Master.FindControl("menu-item-about"), HtmlGenericControl)
myControl.Attributes.Add("class", "current_page_item")
I tried the same code, just to test if I could add a class attribute to the BODY tag and that worked ok.
So why doesn't it work for the LI tag? Is it because it's a sub-item of something else?