Access an HTML control on ASP Master Page from the code behind of a Content Page

后端 未结 3 1470
醉酒成梦
醉酒成梦 2021-01-07 08:08

I have an ASP.NET / C# application in which the Master Page contain the main menu of my application and several content pages that depend of this master page.

I woul

相关标签:
3条回答
  • 2021-01-07 08:33

    Was messing around with this for a while as I needed it to be a HTML link. Turns out that you need runat="server" in the e.g.

    <head runat="server" id=aHead>
    
    0 讨论(0)
  • 2021-01-07 08:37

    Just for a reference, I needed to do something similar and in order to get it working I added the runat="server" to the body tag (thanks to this thread).

    0 讨论(0)
  • 2021-01-07 08:51

    By the way, try

    (HtmlGenericControl)currentMenu = (HtmlGenericControl) Master.FindControl("idOfTheLinkToHighlight");
    currentMenu.Attributes.Add("class", "selected");
    

    it should work because HtmlGenericControl has also attributes

    0 讨论(0)
提交回复
热议问题