tags:

views:

23

answers:

1

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 ? Plz help..thnx

+3  A: 

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 (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;
    }
}
Jon Skeet
@Jon..I have added this code inside of Page_Load event only
Serenity
I go with Jon's answer. Otherwise this error message is not possible. Check the placement of your code and check the placement and existence of the braces ({})
Mario The Spoon
@user289524: As Mario says, that's what the error message is about. I suggest you keep a backup of your code, and then remove everything extraneous until you've got nothing but the class declaration and enough of Page_Load to show the error. I'm sure when you start removing bits, you'll find the error.
Jon Skeet
it was curly brace issue..resolved it..thnx :)
Serenity