简体   繁体   English

错误::类,结构或接口成员声明中的无效令牌'='

[英]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.

相关问题 令牌无效 ';' 在类,结构或接口成员声明中 - Invalid token ';' in class, struct, or interface member declaration 令牌无效 ';' 在类struct或接口成员声明中 - invalid token ';' in class struct or interface member declaration 类、结构或接口成员声明中的无效标记“}” - Invalid token '}' in class, struct, or interface member declaration 类、结构或接口成员声明中的无效标记“)”和“{” - Invalid token ')' and '{' in class, struct, or interface member declaration 类,结构或接口成员声明中的令牌'='无效 - Invalid Token '=' in class,struct or interface member declaration 类、结构或接口成员声明中的无效标记 - Invalid token in class, struct, or interface member declaration 我在类,结构或接口成员声明中收到错误的无效令牌'{' - i get error Invalid token '{' in class, struct, or interface member declaration 错误:类,结构或接口成员声明中的无效令牌“ =” - Error: Invalid token '=' in class, struct, or interface member declaration 类,结构或接口成员声明中的标记'='无效,类,结构或接口成员声明中的无效标记'(' - Invalid token '=' in class, struct, or interface member declaration, Invalid token '(' in class, struct, or interface member declaration class、结构或接口成员声明中的无效令牌“令牌” - Invalid token 'token' in class, struct, or interface member declaration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM