Search code examples
c#asp.netmaster-pages

Accessing <li> tag, ASP.Net


I'm trying to access a <li> tag in my first master page file. I tried FindControl(..) but it allways returns null.

Structure:

  • First Master Page (which contains <li id="element" runat="server">
  • Second Master Page
  • Default.aspx (need to access here)

What do I need to do to access the li element?


Solution

  • You would usually access a server-side control like so:

    Page.Master.FindControl("controlID");
    

    However, if your tag is not set to runat="server", you'll have to find it another way, such as getting the resulting Response.Content and changing it at some point.

    EDIT: Since you're using nested master pages, you may need to go further back in the control hierarchy if you want to reach the "root" master and find a control in it.

    Maybe: Control li = Page.Master.Master.FindControl("controlID")