back button causes NullReferecenException

S

Steve

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
 
S

Steve

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.
 

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

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top