C# – How to access a user control in a masterpage from a content page

asp.netcmaster-pagesuser-controls

Lets say that I have a header user control in a master page, and want to change a property of the user control depending on what content page is loaded inside of the master page. How might I go about this?

Thanks!

Best Answer

You can use two methods. The first is by using Page.Master.FindControl('controlID'). Then you can cast it to the type of your user control. The second method is by adding a <%@ MasterType VirtualPath=""> OR <%@ MasterType TypeName=""%> tag to your aspx page. In the VirtualPath add the virtual path to the master page, or the class in the TypeName. You can then access everything with intellisense.