I have this code to add the class:
(Master.FindControl("ControlName")).Attributes.Add("class", "menu-selected");
But this doesn’t work for the link:
<a href="Default.aspx" id="mnuHome" runat="server">Home</a>
But throws the error:
‘System.Web.UI.Control’ does not
contain a definition for ‘Attributes’
and no extension method ‘Attributes’
accepting a first argument of type
‘System.Web.UI.Control’ could be found
(are you missing a using directive or
an assembly reference?)
I could turn all my links into Hyperlink server controls but this gets really messy, I’d rather keep it like this if possible. Is it?
You need to cast your control:
UPDATE
It is
HtmlAnchor, not the previously stateHtmlGenericControl.