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!
To access the master page controls we need to use the Master key word then call the Property method of control. As we use Master. EnterNameTextBox() to access the master page EnterName textbox and Master. SendDataToContentPageButton() method is used to acees master page button.
To access members of a specific master page from a content page, you can create a strongly typed reference to the master page by creating a @ MasterType directive. The directive allows you to point to a specific master page. When the page creates its Master property, the property is typed to the referenced master page.
c# - Accessing masterpage property from a usercontrol - Stack Overflow.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With