错误::类、结构或接口成员声明中无效标记“=”

2024-04-19

尝试使用以下代码隐藏我的内容页面中的母版页面板

 Panel p = this.Master.FindControl("panel1") as Panel;  
 p.Visible = false; //Error is showing on this line

为什么会出现这个错误?


我怀疑你有这样的代码:

class MyPage : Page
{
    Panel p = this.Master.FindControl("panel1") as Panel;  
    p.Visible = false;
}

您不能像这样将代码放入类中 - 除了声明(例如字段)之外的所有内容都需要位于方法中:

class MyPage : Page
{
    public void Page_Load(object sender, EventArgs e)
    {
        Panel p = this.Master.FindControl("panel1") as Panel;  
        p.Visible = false;
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

错误::类、结构或接口成员声明中无效标记“=” 的相关文章

随机推荐