[英]Error ::Invalid token '=' in class, struct, or interface member declaration
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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.