473,406 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

back button causes NullReferecenException

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
Nov 18 '05 #1
1 1293
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. ThenI 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
.

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Matt MC | last post by:
Hello, Is there anyway to detect when the back button has been pushed? I have three frames, and it requires three pushes of the back button to get back to the previous "window". I would like...
1
by: Peter D. Dunlap | last post by:
Hello, I realize that this may not be the best place to ask this question, through the application is asp.net. I also realize that questions about disabling the back button are generally met...
4
by: szabelin | last post by:
Hello, how do I do history back when asp:button is clicked? I can't use <input button> - I have to use asp:button. Thanks!
2
by: John | last post by:
Hi, I have a web form accounting app. In certain instances it causes trouble if the user clicks the Back button. I've read several posts that indicate that it is not recommended (or even...
3
by: Rosanne | last post by:
Is there a way to clear the SelectedIndex of a listbox when the browser's back button is clicked? I have a page that contains a server side list box with AutoPostBack = True. When the user...
1
by: =?Utf-8?B?QWxCcnVBbg==?= | last post by:
I have a form containing three AJAX UpdatePanels, two of which contain a pair of listboxes and a pair of buttons, with the third one containing a pair of radio buttons in a radiobutton list and...
4
by: bendlam | last post by:
I have a page that contains search criteria and when you click on the search button it causes a post back that populates a dataview on the same page. One of the gridview columns contains a link...
6
by: mcl | last post by:
I have a domain name which is set up for web forwarding with a frame. I have a link on one of the site's pages to an external site. When I select the link the external site is displayed correctly...
8
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
I the page knows there was a cross post back. but i can not find the control. (asp.net 3.5) calling page has a master calling control: <asp:Button ID="btnSendAlert" runat="server" Text="Go"...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.