473,568 Members | 2,738 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 5485
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
9083
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'...
3
3049
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...
4
9014
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...
1
8365
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...
0
1239
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...
3
2419
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
11581
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...
2
2909
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
13038
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...
0
7604
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...
0
8117
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7660
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...
0
6275
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...
1
5498
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
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...
0
3651
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...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.