473,734 Members | 2,724 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

AutoPostBack + SelectedIndexCh anged event bad behavior in ASP.NET

rdb
VB.NET web program with a webform w/2 dropdownlistbox es, set to AutoPostBack
TRUE, selection in either dropdown fires the SelectedIndexCh anged 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 SelectedIndexCh anged 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.I tems.Add("DropD ownList1 Line 1 Selected")
DropDownList1.I tems.Add("DropD ownList1 Line 2 Selected - Go To
Webform2")
DropDownList1.I tems.Add("DropD ownList1 Line 3 Selected")

DropDownList2.I tems.Add("DropD ownList2 Line 1 Selected")
DropDownList2.I tems.Add("DropD ownList2 Line 2 Selected")
DropDownList2.I tems.Add("DropD ownList2 Line 3 Selected")
EndIf
End Sub

Private Sub DropDownList1_S electedIndexCha nged(ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles
DropDownList1.S electedIndexCha nged

If DropDownList1.S electedItem.Tex t = "DropDownLi st1 Line 1 Selected"
Then
Label3.Text = DropDownList1.S electedItem.Tex t()
End If
If DropDownList1.S electedItem.Tex t = "DropDownLi st1 Line 2 Selected
- Go To Webform2" Then
Label3.Text = DropDownList1.S electedItem.Tex t()

Response.Redire ct("http://localhost/VB_WebNavigatio n/Webform2.aspx")
End If
If DropDownList1.S electedItem.Tex t = "DropDownLi st1 Line 3 Selected"
Then
Label3.Text = DropDownList1.S electedItem.Tex t()
End If
End Sub

Private Sub DropDownList2_S electedIndexCha nged(ByVal sender As
System.Object, ByVal e As System.EventArg s) Handles
DropDownList2.S electedIndexCha nged
REM event to process the selections

If DropDownList2.S electedItem.Tex t = "DropDownLi st2 Line 1 Selected"
Then
Label3.Text = DropDownList2.S electedItem.Tex t()
End If
If DropDownList2.S electedItem.Tex t = "DropDownLi st2 Line 2 Selected"
Then
Label3.Text = DropDownList2.S electedItem.Tex t()
End If
If DropDownList2.S electedItem.Tex t = "DropDownLi st2 Line 3 Selected"
Then
Label3.Text = DropDownList2.S electedItem.Tex t()
End If
End Sub

Thanks! --
Roger Briggs
ASNA Technical Support Analyst
Nov 19 '05 #1
2 5497
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
SelectedIndexCh anged.

Think of it this way,
AutoPostBack=tr ue isn't what makes the event handler fire, it's the fact
that the value has changed. That's why if you set AutoPostBack=fa lse and
have a button postback, the SelectedIndexCh anged 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="javas cript">
document.getEle mentById("DropD ownList1").sele ctedIndex = 0;
</script>

in your page will solve the problem...thoug h 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!)
"jasonkeste r" <ja*********@gm ail.com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.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
9093
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 and the 2nd dropdown (spaces) is updated. However, 'spaces' no longer has a SelectedIndexChanged event. Where did it go to? If I change 'spaces' (2nd dropdown) before it gets updated by the 1st (sites), its SelectedIndexChanged is fired and the...
3
3060
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 for ViewState and True for AutoPostBack, it does reload the page but does not call the SelectedIndexChanged event. If I put the ViewState to True then it is called. Does this mean that I cannot get that event and deal with it in better code
4
9047
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 to the server WITHOUT the validators invoking their validation. It seems that the easiest solution would have been for MS to simply give the DropDownList control a "CausesValidation" property, but it does not have one. How can I invoke the...
1
8419
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 I want to do is to allow the user to click on the row that corresponds to the correct address, and have the code behind populate the form's Address1, Address2 etc. controls with the relevant data items. I put the code for this into the...
0
1246
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 down has two items and AutoPostBack is set to true. When a user selects an item in the first drop down, the values for the second drop down are filled in the SelectedIndexChanged event depending on what the user selected. Simple stuff. The pages...
3
2429
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
11609
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 'autopostback=true'? For example, I set up a textbox control with autopostback=false, and a command button. If I run my page (main.aspx) I can type data into the textbox control, then click on the button. The Button1_Click event fires immediately. ...
2
2915
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
13051
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 (selectedindexchanged). I have tried adding an onchange attribute "return confirm('sure u wanna change this?';") but it will not postback regardless of the confirm result and the value in the list does not revert back if cancel selected. Is there a solution?
0
8776
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9449
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9236
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.