Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Question of Scope...

Reply
Thread Tools

Question of Scope...

 
 
Ferret Face
Guest
Posts: n/a
 
      10-18-2005
Hello, Folks!

I have a large number of web object appearing on the same page so I decided to break them down into a number of panels with some control buttons like "Prev" and "Next" to make the appropriate panel visible. To help accoplish this I assign the panels to a panel array. Well I'm getting "Object reference not set to an instance of an object." as an error message causing me to go, "WTF!?"

Can anyone shed some light on this problem?

TIA...

Here's my code:

Imports ...blah, blah, blah.

Public Class ClinicalTrials
Inherits Page

'Declare web objects
Protected lblWarnings as Label
Protected pnlClinicalTrials1 as Panel
Protected pnlClinicalTrials2 as Panel
Protected pnlClinicalTrials3 as Panel
Protected pnlClinicalTrials4 as Panel
Protected pnlClinicalTrials5 as Panel
Dim PgArray() as Panel = {pnlClinicalTrials1, pnlClinicalTrials2, pnlClinicalTrials3, _
pnlClinicalTrials4, pnlClinicalTrials5}
....

Private Sub btnNext_Click(sender as Object, e as EventArgs) Handles btnNext.Click
'Make next page (or panel) visible
Dim i as Integer
Dim j as Integer

lblWarnings.Style("color") = "black"
lblWarnings.Text = ""
Try
'Find which is visible
For i = 0 to UBound(PgArray)
If PgArray(i).Visible Then
j = i
Exit For
End If
Next

'Addition of one
j = (j + 1) Mod (UBound(PgArray) + 1)

'Make next panel visible
For i = 0 to UBound(PgArray)
If (i = j) Then
PgArray(i).Visible = True
Else
PgArray(i).Visible = False
End If
Next
Catch err as Exception
lblWarnings.Style("color") = "red"
lblWarnings.Text = ""& err.Message &" Please contact Client Services to report this error. (btnNext_Click)"
End Try
End Sub
....

End Class

 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      10-18-2005
So much better if you gave us the actual line corresponding to the error.

There are a number of places that could be the error, but...

are there actually panel's with an id of pnlClinicalTrials1, pnlClinicalTrials2, ... in your aspx file?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Ferret Face" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
Hello, Folks!

I have a large number of web object appearing on the same page so I decided to break them down into a number of panels with some control buttons like "Prev" and "Next" to make the appropriate panel visible. To help accoplish this I assign the panels to a panel array. Well I'm getting "Object reference not set to an instance of an object." as an error message causing me to go, "WTF!?"

Can anyone shed some light on this problem?

TIA...

Here's my code:

Imports ...blah, blah, blah.

Public Class ClinicalTrials
Inherits Page

'Declare web objects
Protected lblWarnings as Label
Protected pnlClinicalTrials1 as Panel
Protected pnlClinicalTrials2 as Panel
Protected pnlClinicalTrials3 as Panel
Protected pnlClinicalTrials4 as Panel
Protected pnlClinicalTrials5 as Panel
Dim PgArray() as Panel = {pnlClinicalTrials1, pnlClinicalTrials2, pnlClinicalTrials3, _
pnlClinicalTrials4, pnlClinicalTrials5}
....

Private Sub btnNext_Click(sender as Object, e as EventArgs) Handles btnNext.Click
'Make next page (or panel) visible
Dim i as Integer
Dim j as Integer

lblWarnings.Style("color") = "black"
lblWarnings.Text = ""
Try
'Find which is visible
For i = 0 to UBound(PgArray)
If PgArray(i).Visible Then
j = i
Exit For
End If
Next

'Addition of one
j = (j + 1) Mod (UBound(PgArray) + 1)

'Make next panel visible
For i = 0 to UBound(PgArray)
If (i = j) Then
PgArray(i).Visible = True
Else
PgArray(i).Visible = False
End If
Next
Catch err as Exception
lblWarnings.Style("color") = "red"
lblWarnings.Text = ""& err.Message &" Please contact Client Services to report this error. (btnNext_Click)"
End Try
End Sub
....

End Class

 
Reply With Quote
 
 
 
 
Ferret Face
Guest
Posts: n/a
 
      10-18-2005
Yes, their ID's are "pnlClinicalTrials1", etc.

The actual error message is:

Object reference not set to an instance of an object.
Please contact Client Services to report this error. (btnNext_Click)

If I didn't have it in the Try ... Catch structure I would get the "Server Error in '/' Application, Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.'" screen. All I know is that the error is in the btnNext_Click event handler. I only have Web Matrix and the output from our test web server. I don't have VS.NET becaue my workplace is too cheap.

I'm pretty sure the problem related to the fact I'm trying to use an array of panels to refer to these objects. I wanted to create a more standardized approach so that I could copy-and-past my code to another page (with multiple panels).

Does any of that help?

Is it due to the fact I'm trying to access this array from a subroutine? That wouldn't make sense since the subroutine part of the same class. These NullReferenceExceptions have been plaging me ever since I touched dotNET! (Grumble!). They don't even tell you what the exact line the error is on.

CODE:

<%@ Page Language="vb" autoeventwireup="false" Src="ClinicalTrials.vb" Inherits="ClinicalTrials" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

....blah, blah, blah!

<body bgcolor="#333333">
<form id="frmClinicalTrials" runat="server">

....blah, blah, blah!

<asp:Label id="lblWarnings" runat="server"></asp:Label>
<aspanel id="pnlClinicalTrials1" runat="server">
<h2><u>Section A</u></h2>
<p>What language(s) are the forms in?</p>
<asp:TextBox id="txtQ1" runat="server" Columns="60" Rows="4" TextMode="MultiLine"></asp:TextBox>

....blah, blah, blah!

</aspanel>
<asp:id="pnlClinicalTrials2" runat="server"></aspanel>

....blah, blah, blah!

</form>
</body>
</html>
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:(E-Mail Removed)...
So much better if you gave us the actual line corresponding to the error.

There are a number of places that could be the error, but...

are there actually panel's with an id of pnlClinicalTrials1, pnlClinicalTrials2, ... in your aspx file?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Ferret Face" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
Hello, Folks!

I have a large number of web object appearing on the same page so I decided to break them down into a number of panels with some control buttons like "Prev" and "Next" to make the appropriate panel visible. To help accoplish this I assign the panels to a panel array. Well I'm getting "Object reference not set to an instance of an object." as an error message causing me to go, "WTF!?"

Can anyone shed some light on this problem?

TIA...

Here's my code:

Imports ...blah, blah, blah.

Public Class ClinicalTrials
Inherits Page

'Declare web objects
Protected lblWarnings as Label
Protected pnlClinicalTrials1 as Panel
Protected pnlClinicalTrials2 as Panel
Protected pnlClinicalTrials3 as Panel
Protected pnlClinicalTrials4 as Panel
Protected pnlClinicalTrials5 as Panel
Dim PgArray() as Panel = {pnlClinicalTrials1, pnlClinicalTrials2, pnlClinicalTrials3, _
pnlClinicalTrials4, pnlClinicalTrials5}
....

Private Sub btnNext_Click(sender as Object, e as EventArgs) Handles btnNext.Click
'Make next page (or panel) visible
Dim i as Integer
Dim j as Integer

lblWarnings.Style("color") = "black"
lblWarnings.Text = ""
Try
'Find which is visible
For i = 0 to UBound(PgArray)
If PgArray(i).Visible Then
j = i
Exit For
End If
Next

'Addition of one
j = (j + 1) Mod (UBound(PgArray) + 1)

'Make next panel visible
For i = 0 to UBound(PgArray)
If (i = j) Then
PgArray(i).Visible = True
Else
PgArray(i).Visible = False
End If
Next
Catch err as Exception
lblWarnings.Style("color") = "red"
lblWarnings.Text = ""& err.Message &" Please contact Client Services to report this error. (btnNext_Click)"
End Try
End Sub
....

End Class

 
Reply With Quote
 
Karl Seguin
Guest
Posts: n/a
 
      10-19-2005
I'm learning something here. Not sure I understand it,but if you move ur array declaration into the Page_Load event, it should work

Obviously the panels are null references when the class is first created, but I'd expect the references to be updated once the panels are instantiated...anyways, it's a simple fix that ought to work for you.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Ferret Face" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
Yes, their ID's are "pnlClinicalTrials1", etc.

The actual error message is:

Object reference not set to an instance of an object.
Please contact Client Services to report this error. (btnNext_Click)

If I didn't have it in the Try ... Catch structure I would get the "Server Error in '/' Application, Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.'" screen. All I know is that the error is in the btnNext_Click event handler. I only have Web Matrix and the output from our test web server. I don't have VS.NET becaue my workplace is too cheap.

I'm pretty sure the problem related to the fact I'm trying to use an array of panels to refer to these objects. I wanted to create a more standardized approach so that I could copy-and-past my code to another page (with multiple panels).

Does any of that help?

Is it due to the fact I'm trying to access this array from a subroutine? That wouldn't make sense since the subroutine part of the same class. These NullReferenceExceptions have been plaging me ever since I touched dotNET! (Grumble!). They don't even tell you what the exact line the error is on.

CODE:

<%@ Page Language="vb" autoeventwireup="false" Src="ClinicalTrials.vb" Inherits="ClinicalTrials" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

...blah, blah, blah!

<body bgcolor="#333333">
<form id="frmClinicalTrials" runat="server">

...blah, blah, blah!

<asp:Label id="lblWarnings" runat="server"></asp:Label>
<aspanel id="pnlClinicalTrials1" runat="server">
<h2><u>Section A</u></h2>
<p>What language(s) are the forms in?</p>
<asp:TextBox id="txtQ1" runat="server" Columns="60" Rows="4" TextMode="MultiLine"></asp:TextBox>

...blah, blah, blah!

</aspanel>
<asp:id="pnlClinicalTrials2" runat="server"></aspanel>

...blah, blah, blah!

</form>
</body>
</html>
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:(E-Mail Removed)...
So much better if you gave us the actual line corresponding to the error.

There are a number of places that could be the error, but...

are there actually panel's with an id of pnlClinicalTrials1, pnlClinicalTrials2, ... in your aspx file?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Ferret Face" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
Hello, Folks!

I have a large number of web object appearing on the same page so I decided to break them down into a number of panels with some control buttons like "Prev" and "Next" to make the appropriate panel visible. To help accoplish this I assign the panels to a panel array. Well I'm getting "Object reference not set to an instance of an object." as an error message causing me to go, "WTF!?"

Can anyone shed some light on this problem?

TIA...

Here's my code:

Imports ...blah, blah, blah.

Public Class ClinicalTrials
Inherits Page

'Declare web objects
Protected lblWarnings as Label
Protected pnlClinicalTrials1 as Panel
Protected pnlClinicalTrials2 as Panel
Protected pnlClinicalTrials3 as Panel
Protected pnlClinicalTrials4 as Panel
Protected pnlClinicalTrials5 as Panel
Dim PgArray() as Panel = {pnlClinicalTrials1, pnlClinicalTrials2, pnlClinicalTrials3, _
pnlClinicalTrials4, pnlClinicalTrials5}
....

Private Sub btnNext_Click(sender as Object, e as EventArgs) Handles btnNext.Click
'Make next page (or panel) visible
Dim i as Integer
Dim j as Integer

lblWarnings.Style("color") = "black"
lblWarnings.Text = ""
Try
'Find which is visible
For i = 0 to UBound(PgArray)
If PgArray(i).Visible Then
j = i
Exit For
End If
Next

'Addition of one
j = (j + 1) Mod (UBound(PgArray) + 1)

'Make next panel visible
For i = 0 to UBound(PgArray)
If (i = j) Then
PgArray(i).Visible = True
Else
PgArray(i).Visible = False
End If
Next
Catch err as Exception
lblWarnings.Style("color") = "red"
lblWarnings.Text = ""& err.Message &" Please contact Client Services to report this error. (btnNext_Click)"
End Try
End Sub
....

End Class

 
Reply With Quote
 
Ferret Face
Guest
Posts: n/a
 
      10-19-2005
I ended up creating the array assignment into the Page_Load event just like you said but I put the declaration "Dim PgArray(4)..." in the same spot.

It seems to work that way.

Thanks.
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:%(E-Mail Removed)...
I'm learning something here. Not sure I understand it,but if you move ur array declaration into the Page_Load event, it should work

Obviously the panels are null references when the class is first created, but I'd expect the references to be updated once the panels are instantiated...anyways, it's a simple fix that ought to work for you.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Ferret Face" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
Yes, their ID's are "pnlClinicalTrials1", etc.

The actual error message is:

Object reference not set to an instance of an object.
Please contact Client Services to report this error. (btnNext_Click)

If I didn't have it in the Try ... Catch structure I would get the "Server Error in '/' Application, Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.'" screen. All I know is that the error is in the btnNext_Click event handler. I only have Web Matrix and the output from our test web server. I don't have VS.NET becaue my workplace is too cheap.

I'm pretty sure the problem related to the fact I'm trying to use an array of panels to refer to these objects. I wanted to create a more standardized approach so that I could copy-and-past my code to another page (with multiple panels).

Does any of that help?

Is it due to the fact I'm trying to access this array from a subroutine? That wouldn't make sense since the subroutine part of the same class. These NullReferenceExceptions have been plaging me ever since I touched dotNET! (Grumble!). They don't even tell you what the exact line the error is on.

CODE:

<%@ Page Language="vb" autoeventwireup="false" Src="ClinicalTrials.vb" Inherits="ClinicalTrials" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

...blah, blah, blah!

<body bgcolor="#333333">
<form id="frmClinicalTrials" runat="server">

...blah, blah, blah!

<asp:Label id="lblWarnings" runat="server"></asp:Label>
<aspanel id="pnlClinicalTrials1" runat="server">
<h2><u>Section A</u></h2>
<p>What language(s) are the forms in?</p>
<asp:TextBox id="txtQ1" runat="server" Columns="60" Rows="4" TextMode="MultiLine"></asp:TextBox>

...blah, blah, blah!

</aspanel>
<asp:id="pnlClinicalTrials2" runat="server"></aspanel>

...blah, blah, blah!

</form>
</body>
</html>
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:(E-Mail Removed)...
So much better if you gave us the actual line corresponding to the error.

There are a number of places that could be the error, but...

are there actually panel's with an id of pnlClinicalTrials1, pnlClinicalTrials2, ... in your aspx file?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Ferret Face" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
Hello, Folks!

I have a large number of web object appearing on the same page so I decided to break them down into a number of panels with some control buttons like "Prev" and "Next" to make the appropriate panel visible. To help accoplish this I assign the panels to a panel array. Well I'm getting "Object reference not set to an instance of an object." as an error message causing me to go, "WTF!?"

Can anyone shed some light on this problem?

TIA...

Here's my code:

Imports ...blah, blah, blah.

Public Class ClinicalTrials
Inherits Page

'Declare web objects
Protected lblWarnings as Label
Protected pnlClinicalTrials1 as Panel
Protected pnlClinicalTrials2 as Panel
Protected pnlClinicalTrials3 as Panel
Protected pnlClinicalTrials4 as Panel
Protected pnlClinicalTrials5 as Panel
Dim PgArray() as Panel = {pnlClinicalTrials1, pnlClinicalTrials2, pnlClinicalTrials3, _
pnlClinicalTrials4, pnlClinicalTrials5}
....

Private Sub btnNext_Click(sender as Object, e as EventArgs) Handles btnNext.Click
'Make next page (or panel) visible
Dim i as Integer
Dim j as Integer

lblWarnings.Style("color") = "black"
lblWarnings.Text = ""
Try
'Find which is visible
For i = 0 to UBound(PgArray)
If PgArray(i).Visible Then
j = i
Exit For
End If
Next

'Addition of one
j = (j + 1) Mod (UBound(PgArray) + 1)

'Make next panel visible
For i = 0 to UBound(PgArray)
If (i = j) Then
PgArray(i).Visible = True
Else
PgArray(i).Visible = False
End If
Next
Catch err as Exception
lblWarnings.Style("color") = "red"
lblWarnings.Text = ""& err.Message &" Please contact Client Services to report this error. (btnNext_Click)"
End Try
End Sub
....

End Class

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
question row filter (more of sql query question) =?Utf-8?B?YW5kcmV3MDA3?= ASP .Net 2 10-06-2005 01:07 PM
Quick Question - Newby Question =?Utf-8?B?UnlhbiBTbWl0aA==?= ASP .Net 4 02-16-2005 11:59 AM
Question on Transcender Question :-) eddiec MCSE 6 05-20-2004 06:59 AM
Question re: features of the 831 router (also a 924 question) Wayne Cisco 0 03-02-2004 07:57 PM
Syntax Question - Novice Question sean ASP .Net 1 10-20-2003 12:18 PM



Advertisments