Question of Scope...

Discussion in 'ASP .Net' started by Ferret Face, Oct 18, 2005.

  1. Ferret Face

    Ferret Face Guest

    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
     
    Ferret Face, Oct 18, 2005
    #1
    1. Advertising

  2. Ferret Face

    Karl Seguin Guest

    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" <> wrote in message news:...
    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
     
    Karl Seguin, Oct 18, 2005
    #2
    1. Advertising

  3. Ferret Face

    Ferret Face Guest

    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>
    "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:...
    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" <> wrote in message news:...
    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
     
    Ferret Face, Oct 18, 2005
    #3
  4. Ferret Face

    Karl Seguin Guest

    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" <> wrote in message news:...
    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>
    "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:...
    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" <> wrote in message news:...
    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
     
    Karl Seguin, Oct 19, 2005
    #4
  5. Ferret Face

    Ferret Face Guest

    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:%...
    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" <> wrote in message news:...
    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>
    "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:...
    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" <> wrote in message news:...
    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
     
    Ferret Face, Oct 19, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Opal
    Replies:
    12
    Views:
    1,005
    Paul Opal
    Oct 11, 2004
  2. ann
    Replies:
    13
    Views:
    696
    Patricia Shanahan
    Sep 13, 2005
  3. Steven T. Hatton
    Replies:
    9
    Views:
    520
  4. Xah Lee
    Replies:
    0
    Views:
    2,283
    Xah Lee
    Feb 26, 2009
  5. Replies:
    0
    Views:
    184
Loading...

Share This Page