Search code examples
c#asp.netvb.netmaster-pages

Add class to ASP.NET MasterPage control


This is the code in my MasterPage:

<li id="liABOUT" runat="server"><a href="About.aspx">ABOUT</a></li>

When I am on another page referencing the MasterPage I want to add a class to this li control, something like this. Cant get it to work. Using ASP.NET 4.5

Me.Master.FindControl("ContentPlaceHolderMaster").FindControl("LiAbout").Attributes.Add("class", "active")

VB.NET or C# Code would be fine


Solution

  • This worked....

    ' Get reference to control located on master page
     Dim lb As HtmlGenericControl = Page.Master.FindControl("liABOUT")
     lb.Attributes.Add("class", "active")