back button causes NullReferecenException

Discussion in 'ASP .Net' started by Steve, Aug 25, 2004.

  1. Steve

    Steve Guest

    Hello,

    In my first (of 2) aspx page I have 2 listboxes. I
    populate the first listbox in the PageLoad event

    If Not IsPostBack Then
    ....

    When I select an item from the first listbox, lst1, the
    2nd listbox gets populated and writes some text to a
    hidden textbox called txtSource. Then I redirect to
    page2.aspx on the selectedItem event of lst2 and pass the
    selections to the next page using Cache("var1") (by the
    way, which is better between passing data -- using cache,
    session or response.Form?). But back to the problem,
    when I click on the back button of the browser from
    page2.aspx I was getting this error:

    Exception Details: System.NullReferenceException: Object
    reference not set to an instance of an object.

    and modified the code where the error was happening. Then
    I could get back to page1.aspx, but when I click on the
    first listbox, lst1, I get the same error as above. Here
    is the code snipet where the error happens

    Sub lst2_Selected...
    Dim strGetFile As String
    If Not txtSource.Text.Equals("") And Not
    lst2.SelectedItem.Value.Equals("") Then
    strGetFile = txtSource.Text & "\" &
    lst2.SelectedItem.Value
    Cache("strFile") = strGetFile
    Response.Redirect("page2.aspx")
    End If
    End Sub

    The error happens at

    If Not txtSource.Text.Equals("") And Not
    lst2.SelectedItem.Value.Equals("") Then

    What is the correct way to refer to txtSource when it is
    empty/null?

    How can I eliminate the above error?

    TIA,
    Steve
     
    Steve, Aug 25, 2004
    #1
    1. Advertising

  2. Steve

    Steve Guest

    OK. I moved the response.Redirect line in the lst2 event
    to a button control. This seems to have fixed the problem
    (for now). It appears that all the listbox events were
    being called when I clicked on the back button, and also
    the page load event of page2.aspx appeared to be getting
    called from the lst1 selected... event. Moving ..redirect
    to the button resolved that. But I suspect there will be
    other not fun things in store with my setup. Any
    suggestions welcome if any sees anything whacky here.




    >-----Original Message-----
    >Hello,
    >
    >In my first (of 2) aspx page I have 2 listboxes. I
    >populate the first listbox in the PageLoad event
    >
    >If Not IsPostBack Then
    >....
    >
    >When I select an item from the first listbox, lst1, the
    >2nd listbox gets populated and writes some text to a
    >hidden textbox called txtSource. Then I redirect to
    >page2.aspx on the selectedItem event of lst2 and pass the
    >selections to the next page using Cache("var1") (by the
    >way, which is better between passing data -- using cache,
    >session or response.Form?). But back to the problem,
    >when I click on the back button of the browser from
    >page2.aspx I was getting this error:
    >
    >Exception Details: System.NullReferenceException: Object
    >reference not set to an instance of an object.
    >
    >and modified the code where the error was happening.

    Then
    >I could get back to page1.aspx, but when I click on the
    >first listbox, lst1, I get the same error as above. Here
    >is the code snipet where the error happens
    >
    >Sub lst2_Selected...
    >Dim strGetFile As String
    >If Not txtSource.Text.Equals("") And Not
    >lst2.SelectedItem.Value.Equals("") Then
    > strGetFile = txtSource.Text & "\" &
    >lst2.SelectedItem.Value
    > Cache("strFile") = strGetFile
    > Response.Redirect("page2.aspx")
    >End If
    >End Sub
    >
    >The error happens at
    >
    >If Not txtSource.Text.Equals("") And Not
    >lst2.SelectedItem.Value.Equals("") Then
    >
    >What is the correct way to refer to txtSource when it is
    >empty/null?
    >
    >How can I eliminate the above error?
    >
    >TIA,
    >Steve
    >.
    >
     
    Steve, Aug 25, 2004
    #2
    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. sylvia sil
    Replies:
    1
    Views:
    657
    Curt_C [MVP]
    Dec 29, 2004
  2. cmay
    Replies:
    0
    Views:
    1,182
  3. Matt MC
    Replies:
    6
    Views:
    590
    Adrienne
    Apr 3, 2005
  4. ScottyinLA
    Replies:
    0
    Views:
    301
    ScottyinLA
    Apr 8, 2006
  5. Matt MC
    Replies:
    6
    Views:
    133
    Thomas 'PointedEars' Lahn
    Apr 5, 2005
Loading...

Share This Page