Question of Scope...

F

Ferret Face

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
 
K

Karl Seguin

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/
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
 
F

Ferret Face

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>
<asp:panel 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!

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

....blah, blah, blah!

</form>
</body>
</html>
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/
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
 
K

Karl Seguin

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/
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>
<asp:panel 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!

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

...blah, blah, blah!

</form>
</body>
</html>
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/
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
 
F

Ferret Face

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.
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/
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>
<asp:panel 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!

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

...blah, blah, blah!

</form>
</body>
</html>
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/
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
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top