Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > back button causes NullReferecenException

Reply
Thread Tools

back button causes NullReferecenException

 
 
Steve
Guest
Posts: n/a
 
      08-25-2004
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
 
Reply With Quote
 
 
 
 
Steve
Guest
Posts: n/a
 
      08-25-2004
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
>.
>

 
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
FileUpload causes error when pressing the browser back button.. ScottyinLA ASP .Net Web Controls 0 04-07-2006 11:49 PM
Back button causes "Internet Explorer cannot open the internet site" cmay ASP .Net 0 08-29-2005 03:56 PM
Frames causes back-button to malfunction..... any remedies? Matt MC Javascript 6 04-05-2005 09:35 PM
Frames causes back-button to malfunction..... any remedies? Matt MC HTML 6 04-03-2005 08:39 AM
disable the back button provide the users with my own button to go back. sylvia sil ASP .Net 1 12-29-2004 04:41 PM



Advertisments