473,320 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Hide Panel

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.
Nov 21 '06 #1
2 1786
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
"Badass Scotsman" wrote:
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.
Nov 21 '06 #2
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.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"Badass Scotsman" <ba****@yo.comwrote in message
news:YQ*****************@text.news.blueyonder.co.u k...
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.

Nov 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Efkas | last post by:
I have a full custom application with some widged extending Controls like Label and PictureBox. I build a menu with these widgets. When I click on one of them, it calls a function to display...
5
by: dje | last post by:
In the OnClick event on a radioButtonList, I run a javascript to show/hide the appropriate div along with a submit button, which displays as expected. The problem is the submit no longer works on...
3
by: Lynn | last post by:
Hello, I have a user control that contains a table, and some text fields. I would like to show or hide a particular row of this table, based on a selection the user makes on my page. Here's...
1
by: roni | last post by:
hi. i have webform with 4 panel that i switch then in wizard style ( asp 1.1) . i want to know if i can hide/show the asp panel control IN THE CLIENT SIDE ? meaning, show panel 1 . user enter...
0
by: Mac via DotNetMonster.com | last post by:
I have a MDI parent form and the only control on it is a panel anchored to the left hand side. I have menu items on the MDI parent that show & hide this panel. Ideally I would like it to show by...
2
by: Nathan Sokalski | last post by:
I have an HTML table in which I am using ASP:Panel controls to group together <tr>'s so that I can more easily show/hide them (by setting the ASP:Panel's Visible property). This works fine, but...
1
by: shapper | last post by:
Hello, I created an Asp:Repeater where I have an Asp:Panel and an Asp:Label. In each record of the repeater I want to have a small button which hides or shows the panel in that record. If...
8
by: active | last post by:
If I create a UserControl that inherits from, say, Panel, and I do not want my UserControl to have a property that it inherits from Panel. How can I remove it. For example, I might not want by...
2
Bob Ross
by: Bob Ross | last post by:
Because of IE6 not being able to put drop downs behind other divs I need to hide the drop downs when the div pops up. The problem is I hide the drop downs but the button is also using an update...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.