Hide Panel

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.
 
G

Guest

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
 
E

Eliyahu Goldin

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top