Method to modify the value of the master page control on the page page after referencing the master page
- 2020-05-30 19:46:50
- OfStack
The specific conditions are as follows:
1. First, the page must refer to the master page to be modified;
2. On the page page, create a strongly typed reference to the master page by setting the page directive @MasterType, and specify the virtual path to generate the strongly typed file, for example:
<%@ MasterType VirtualPath="~/Demo.Master" %>
3. Add an public property to the master page and assign the set value to the master page control, for example:
public string PageTitle
{
set {
this.LabPageTitle.Text = value;
}
}
After the above conditions are met, you can modify the value of the control above the master page on the page page, for example:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.Master.PageTitle = "Page Page modifies the value of the master page control ";
}
}
The LabTitle control value on the Master page is then set to "Page page modifies the master page control value.