Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
186
rated 0 times [  192] [ 6]  / answers: 1 / hits: 68673  / 13 Years ago, thu, october 27, 2011, 12:00:00

I have the following markup:



<asp:DropDownList ID=dd1 AutoPostBack=true runat=server>
<asp:ListItem Value=1>1</asp:ListItem>
<asp:ListItem Value=2>2</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID=dd2 AutoPostBack=true onchange=javascript:return true; runat=server>
<asp:ListItem Value=1>3</asp:ListItem>
<asp:ListItem Value=2>4</asp:ListItem>
</asp:DropDownList>


Wired up to this:



Protected Sub changed1(sender As Object, e As EventArgs) Handles dd1.SelectedIndexChanged

End Sub

Protected Sub changed2(sender As Object, e As EventArgs) Handles dd2.SelectedIndexChanged

End Sub


When dd2's index is changed, you'd expect its handler to fire, right? Well, it doesn't. Instead, it gets queued up and is fired after dd1's handler fires when its index is changed. If you take the onchange=javascript:return true; off dd2, it fires just fine.



Does anyone have any idea what's happening here?



Edit: My first answer would be that using return expressions on a dropdownlist doesn't work the same as a button's click event, but I swear I've done this with dropdownlists before.



Update: I am able to force the server event to fire by doing this in Javascript:



__doPostBack(<%=dd2.ClientID %>, '');



I don't see why I have to do this, but it works. However, I still want to do it the other way, so if someone knows, please let me know so I can mark you as answer.


More From » asp.net

 Answers
9

For some reason, I thought you could cancel a dropdown's server event by returning false on the client side's onchange event like you could with a button's onclick event (eg, onclick=javascript:return false;).



What I ended up doing is checking a condition in a function. If true, it fires this:



__doPostBack(<%=dd2.ClientID %>, '');



Otherwise, it doesn't.


[#89418] Wednesday, October 26, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jackelyn

Total Points: 303
Total Questions: 103
Total Answers: 102

Location: Turks and Caicos Islands
Member since Sun, Mar 7, 2021
3 Years ago
jackelyn questions
Thu, Apr 8, 21, 00:00, 3 Years ago
Sun, Feb 28, 21, 00:00, 3 Years ago
Mon, May 25, 20, 00:00, 4 Years ago
Thu, Apr 30, 20, 00:00, 4 Years ago
;