Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change visible of an asp.net control of master page in content page?

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.

like image 889
Hamid Talebi Avatar asked May 07 '13 11:05

Hamid Talebi


People also ask

How do you access a public property defined in a master page from the content page?

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.


1 Answers

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

like image 129
RMalke Avatar answered Sep 16 '22 13:09

RMalke