错误::无效令牌'='类,结构或接口成员声明 [英] Error ::Invalid token '=' in class, struct, or interface member declaration
本文介绍了错误::无效令牌'='类,结构或接口成员声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试使用以下code隐藏母版页在我的内容页面板
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 ?
推荐答案
我怀疑你已经得到了code是这样的:
I suspect you've got the code like this:
class MyPage : Page
{
Panel p = this.Master.FindControl("panel1") as Panel;
p.Visible = false;
}
您不能只是把code类中的那样 - 一切比声明(如字段)其他需要在一个方法:
You can't just put code in the class like that - everything other than declarations (e.g. 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;
}
}
这篇关于错误::无效令牌'='类,结构或接口成员声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文