Find Master Page Control In Content Page

  • Home
  • News

If I have understood this correctly…

If your list is on the master page…

  • Home
  • News

…then you can do this on your content page…

Control list = this.Page.Master.FindControl(“list”);

Then the li objects will be controls in the list object – e.g. list.Controls. Or you can do…

Control home = this.Page.Master.FindControl(“list”).FindControl(“home”);

…to find specific controls of the list control.

When using the runat=”server” on the HTML controls the server side equivalent object will be HtmlGenericControl.

If you want to apply a class to the LI tags what you would have to do is cast the LI object to a HtmlGenericControl and then use the Attributes property. For example…

HtmlGenericControl home = (HtmlGenericControl)this.Page.Master.FindControl(“list”).FindControl(“home”);

home.Attributes[“class”] = “className”;

Share