tags:

views:

113

answers:

3

I have an AJAX problem. There are some button on the ASP.NET page that I think gets disabled and re-enabled on a postback, which needs to be done for other reasons. There are 2 dropdown menus inside an updatepanel that will use the AJAX. The first dropdown menu updates the second one. There is a client side onblur on the first dropdown that calls the __doPostBack and the server call to the onselectedindexchanged event handler is called if something changed in the dropdown list. The problem is if the client onblur event happens too quickly it seems like the postback happens too fast and the buttons stay disabled.

For example, this happens if the user tabs through the dropdown list quickly. I've read that this is an AJAX issue if the server response is a little slow and the partial rendering messes things up.

Does anyone have a solution for this?

A: 

A generic solution can be to use a counter with the control; decrement and disable only if <= 0, increment and enable if > 0. :) The ++/-- operators may not be guaranteed atomic, but they are "good enough".

vladr
A: 

Hard to say without some code to look at, but... Remember what the first letter of AJAX stands for: Asynchronous. You can't gaurantee when your callback method is actually going to execute. Or, if you make two calls (A then B), you might be getting back a response A then B... but next time it's B then A.

Bryan
A: 

Maybe you could use a boolean variable which you flag while your waiting for the AJAX method to complete and check before you run the code in the onselectedindexchanged event method. That way the onselectedindexchanged event method won't do anything if the AJAX method hasn't finished.

Daniel