473,406 Members | 2,956 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.

AutoPostBack + SelectedIndexChanged event bad behavior in ASP.NET

rdb
VB.NET web program with a webform w/2 dropdownlistboxes, set to AutoPostBack
TRUE, selection in either dropdown fires the SelectedIndexChanged events
correctly UNTIL I navigate to second webform in the same project, THEN use
the Back button to return to first webform; then changing the selection of
the second dropdownlistbox fires the SelectedIndexChanged event for the FIRST
dropdownlistbox.

I realize that a) using an eventhandler for both events, and b) setting
AutoPostBack to FALSE may resolve this issue; HOWEVER, this appears to be a
big fat .NET Framework bug in my VB.NET application. Anyone experience this
bad behavior? The application that demonstrates this is available upon
request, but code is only

Private Sub Page_Load...
If Not (Me.IsPostBack) Then

DropDownList1.Items.Add("DropDownList1 Line 1 Selected")
DropDownList1.Items.Add("DropDownList1 Line 2 Selected - Go To
Webform2")
DropDownList1.Items.Add("DropDownList1 Line 3 Selected")

DropDownList2.Items.Add("DropDownList2 Line 1 Selected")
DropDownList2.Items.Add("DropDownList2 Line 2 Selected")
DropDownList2.Items.Add("DropDownList2 Line 3 Selected")
EndIf
End Sub

Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DropDownList1.SelectedIndexChanged

If DropDownList1.SelectedItem.Text = "DropDownList1 Line 1 Selected"
Then
Label3.Text = DropDownList1.SelectedItem.Text()
End If
If DropDownList1.SelectedItem.Text = "DropDownList1 Line 2 Selected
- Go To Webform2" Then
Label3.Text = DropDownList1.SelectedItem.Text()

Response.Redirect("http://localhost/VB_WebNavigation/Webform2.aspx")
End If
If DropDownList1.SelectedItem.Text = "DropDownList1 Line 3 Selected"
Then
Label3.Text = DropDownList1.SelectedItem.Text()
End If
End Sub

Private Sub DropDownList2_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DropDownList2.SelectedIndexChanged
REM event to process the selections

If DropDownList2.SelectedItem.Text = "DropDownList2 Line 1 Selected"
Then
Label3.Text = DropDownList2.SelectedItem.Text()
End If
If DropDownList2.SelectedItem.Text = "DropDownList2 Line 2 Selected"
Then
Label3.Text = DropDownList2.SelectedItem.Text()
End If
If DropDownList2.SelectedItem.Text = "DropDownList2 Line 3 Selected"
Then
Label3.Text = DropDownList2.SelectedItem.Text()
End If
End Sub

Thanks! --
Roger Briggs
ASNA Technical Support Analyst
Nov 19 '05 #1
2 5469
This is just wishful thinking on your part. Once the user starts
monkeying with the back button, all bets are off. It has always been
this way for CGI programming, and ASP.NET has neither improved nor
broken it.

ASP.NET, and all server side technologies run on the web server.
Browser page caching happens on the browser. There is no way around
this short of instructing the browser not to cache your pages. There
are hacks and workarounds, such as javascript history.go(1);'s at the
top of every page. But for the most part, you just have to build your
application to deal with the fact that it lives in a browser that
contains a Back button.

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com

Nov 19 '05 #2
Just to shed some lihgt on what's happening...

The 1st dropdownlist isn't firing because it's being posted back (clearly,
the 2nd one is doing the postback). Instead, it's firing because it's value
has changed from the initial value, which is the true meaning on
SelectedIndexChanged.

Think of it this way,
AutoPostBack=true isn't what makes the event handler fire, it's the fact
that the value has changed. That's why if you set AutoPostBack=false and
have a button postback, the SelectedIndexChanged handler will still fire IF
the value changed.

Notice when you hit back, the value in the 1st dropdown is still the 2nd
item, which means it's index did changed from the initial value (which was
the 1st item).

Simply putting:
<script language="javascript">
document.getElementById("DropDownList1").selectedI ndex = 0;
</script>

in your page will solve the problem...though I wouldn't consider it the
solution. The solution is that you understand what's really going on (it
isn't a bug), and why the simple solution above works...it might not work in
all cases and it might have other sideffects...I'm only telling you about it
so you can get an understanding of what's happening.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"jasonkester" <ja*********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
This is just wishful thinking on your part. Once the user starts
monkeying with the back button, all bets are off. It has always been
this way for CGI programming, and ASP.NET has neither improved nor
broken it.

ASP.NET, and all server side technologies run on the web server.
Browser page caching happens on the browser. There is no way around
this short of instructing the browser not to cache your pages. There
are hacks and workarounds, such as javascript history.go(1);'s at the
top of every page. But for the most part, you just have to build your
application to deal with the fact that it lives in a browser that
contains a Back button.

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com

Nov 19 '05 #3

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

Similar topics

1
by: Donal | last post by:
I have 3 related dropdowns. When the 1st is changed, the 2nd is updated, and when the 2nd is changed, the 3rd is updated. When i change the 1st dropdown (sites), the SelectedIndexChanged fires...
3
by: Lloyd Sheen | last post by:
I have a page that works fine. I am trying to optimize the page by overriding some of the Information that is being saved in the hidden VIEWSTATE. If I make the properties of the dropdown False...
4
by: Scott M. | last post by:
If I put RequiredFiledValidators on a page and set them up with corresponding TextBoxes everything works just fine. If I add a DropDownList and set its AutoPostBack to True, I am able to post data...
1
by: Edward | last post by:
I am having a terrible time getting anything useful out of a listbox on my web form. I am populating it with the results from Postcode lookup software, and it is showing the results fine. What...
0
by: Scott | last post by:
Hi. I'm having some problems with AutoPostBack in my asp.net pages running on Windows 2003/IIS 6. The pages are really simple. For example, one of them contains two dropDownLists. The firstdrop...
3
by: Dabbler | last post by:
How do I tell wether I'm seeing autopostback vs submit button click in Page_load? Thanks for any clues.
2
by: Tom Edelbrok | last post by:
Question: Why does a button event (ie: Button1_Click) get executed on the first click for a textbox control which has 'autopostback=false', but doesn't get executed until a second click when...
2
by: teo | last post by:
I have a Listbox, if I set EnableViewStarte = False the AutopostaBack fired by SelectedIndexChanged doesn't work. The 'SelectedIndexChanged' event should call
5
by: robert | last post by:
I have a dropdownlist with the autopostback set to true. I want the user to be confirm whether they do indeed want to change the value, which on post back fires a server side event...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
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.