I have a Master Page
that have a asp:Panel
control and the code that sets Visible = False
in it's code behind.
Now i want to change Visible = True
in one of content page. How do it?
Master page code behind:
AccountUserInfo.Visible = false;
Content page code behind:
((Panel)Master.FindControl("AccountUserInfo")).Visible = true;
Apparently content page's code behind don't work.
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.
The master page code that set the control to Visible = False
is being executed after the code on the page.
Try to place the page code on the PreRender
event. It is the one of the last events of the cycle:
protected override void OnPreRender(EventArgs e)
{
((Panel)Master.FindControl("AccountUserInfo")).Visible = true;
base.OnPreRender(e);
}
Also, take a look at this ASP.NET Page Life Cycle Diagram
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