trying to hide a panel of Master Page in my content page using the following code
Panel p = this.Master.FindControl("panel1") as Panel;
p.Visible = false; //Error is showing on this line
Why this error ?
I suspect you've got the code like this:
class MyPage : Page
{
Panel p = this.Master.FindControl("panel1") as Panel;
p.Visible = false;
}
You can't just put code in the class like that - everything other than declarations (eg fields) needs to be in a method:
class MyPage : Page
{
public void Page_Load(object sender, EventArgs e)
{
Panel p = this.Master.FindControl("panel1") as Panel;
p.Visible = false;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.