Hide Panel

  • Thread starter Thread starter Badass Scotsman
  • Start date Start date
B

Badass Scotsman

Hello,

I have two files, default.aspx and default.aspx.cs. On my ASPX file I have
the following code:

<asp:panel ID="MyPanel" runat="server">
Content Here
</asp:panel>

And I want to hide this panel when I run my Button_Click routine, which is
coded within my .CS file as so:

***************************
using blah blah blah;
protected Panel MyPanel;
public void Button_Click(Object sender, EventArgs e)
{
if (Page.IsValid)
{
MyPanel.Visible = false;
}
}
***************************

I keep getting the following error:

***************************
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
Source Error:
Line 41: {
Line 42: base.OnInit(e);
Line 43: MyPanel.Visible = false;
Line 44: }
Line 45:
***************************

Im still earning this and I am at a very early stage, any help appreciated,

Gary.
 
you should debug it ...
in normal case it see inposible but its clear that there is an mistake which
u did.
debug debug and learn..

--
Esref DURNA
Software Engineer

www.esrefdurna.com
An Asp.Net , C# Turkish Cypriot lover
 
Gary,

Are you using asp.net 2.0 or 1.1?

My guess you are using 2.0. In 2.0 the code-behind doesn't need to have
declarations of the controls declared in the .aspx file. In fact, the line
protected Panel MyPanel; hides the one in the panel declared .aspx file. And
you never create another instance of Panel class to assign it to the MyPanel
reference. And that is not what you want. Just remove this line and see if
it works.
 
Back
Top