Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 15th, 2006, 12:42 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default Wrong DD SelectedIndexChanged fires

I have two .NET drop down controls with AutoPostBack=True for both. I change the value in the first, and its SelectedIndexChanged event in the code behind fires and redirects me to another page based on the selected value. I hit back and the selection screen is again displayed, with the value still selected in the first drop down as would be expected. I then change the value in the second dd but the SIC event for the first one fires again, and the SIC for the dd I've just changed does not.

But, if I change the second dd first, its event fires OK. So I know it works. But if I then change the first dd, go back, and change the second one again, the first one's SIC event fires and the one I've just changed is ignored again, just as described above.

IOW, it's acting like regardless of the fact that I've changed the second DD, I really changed the first one, and it then ignores the second dd change. I've also got a text field on this form where a value could be entered (isntead of selecting from the dds). Beside it is a button with similar code. Even this code is not working properly once I've changed the first dd list.

I've tried to work around this bizarre behavior by clearing the selected value in the Form_Load event thinking this would clear the selection when the user clicks back. But for some strange reason the Page_Load is run when the AutoPostBack is issued as well as when the user hits back, and it clears the value BEFORE the SIC event for the changed dd can fire and then there's no value selected to pass to the redirected page. I tried turning off enableviewstate and then the events don't fire at all (which I can understand but I was trying anything I could think of to fix this). And I've tried rebuilding the drop down lists in case VS did something weird and confused itself, as often seems to happen. But nothing seems to help.

Can somebody please explain why it behaves this way and what I can do to make the correct event fire depending on which dd was selected (or button pushed) regardless of whether the first dd was changed previously? This just doesn't make sense to me.
 
Old February 17th, 2006, 09:34 AM
Authorized User
 
Join Date: Jun 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think it has something to do the Browser behaviour - the Back button in IE is supposed to take you Back to the previous page i.e. the history of your browsing.

I'd made a nice big hard to miss BACK button and then the page will load again.

Of course I could be wrong...
 
Old February 17th, 2006, 10:11 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

Unfortunately I can't ensure the users won't still use the browser's back button. So I'm devising a work around, as usual. I've reduced the form to a single postback button, am using hidden fields to maintain my own form state as .NET is evidently having trouble maintaining its, reduced the page to a sinlge postback button, and am writing script to show/hide the various elements as necessary and restore the page the way I want it when the user goes back.

It's hard to believe that I have to jump through so many hoops to do something that would require a single line of code in a Windows app, but that seems to be the nature of developing for the web.
 
Old March 7th, 2006, 12:11 AM
Registered User
 
Join Date: Mar 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ron,

Did you ever manage a solution to this one? It took me a bit of searching (more than usual) to find someone with my same situation. I'm going down the path of some sort of javascript that clears other dropdowns when it is changed. Just curious if you'd found a better way.

Erik
 
Old March 7th, 2006, 12:14 AM
Registered User
 
Join Date: Mar 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

oh and not sure it matters, but I'm seeing this behavior in ASP.NET 2.0
 
Old March 8th, 2006, 08:21 AM
Registered User
 
Join Date: Mar 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I also have this exact problem scenario that you describe, Ron. There must be a simple solution to this! Anyone?!

 
Old March 9th, 2006, 04:03 AM
Registered User
 
Join Date: Mar 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I finally found a workaround that handles my situation. It involves some client side javascript that clears out all other dropdowns as part of some custom "onchange" handling. Here's the web page that inspired me (See Stephen Balkum's response on 9/16/03):

http://tinyurl.com/ef98q
 
Old March 9th, 2006, 10:32 AM
Registered User
 
Join Date: Mar 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Erik_J, that fixed my problem! :)






Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView Delete Event fires twice Scott663 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 May 11th, 2007 05:36 AM
Convert date String (dd/mm/yy) to dd- Month- yy minhpx J2EE 2 March 6th, 2007 08:29 AM
MouseOut event fires constantly MrSander BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 0 May 3rd, 2006 11:09 AM
Session_Start fires twice!!? Dmitriy Pro VB 6 1 March 17th, 2005 12:59 PM
Session Listener Fires On Every Request bwinspur Apache Tomcat 1 October 24th, 2004 11:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.