views:

527

answers:

4

On a rather complicated screen with a big updatepanel, I'm running into the following problem:

If a user clicks on a certain button 6 or 7 times really fast, it seems to eventually process the last request out of turn and problems occur. Specifically, there's an xml document in session state, and it gets out of sync.

What I really want to do is block clicks to this button until the postback completes. I know I could probably find an easy way to do this with Javascript, but it seems like it might be built-in.

Any thoughts?

Note: The answers below are helpful, but they haven't solved the problem. After disabling the linkbutton with onClientClick and then allowing it to come back after the postback enabled again, the problem persists. It's almost as if the updatepanel isn't quite done with everything even though it has drawn the fresh, enabled linkbutton on the screen.

More notes (solved!): I solved this one by using BlockUI (jQuery plugin). See my answer below.

+1  A: 

UpdatePanel? I will assume you are using MS AJAX, if so I will recommend you download the AJAX toolkit if you have not done so. This toolkit comes with many ready to use controls, and extensions to help you in your AJAX enabled app. For example, there is one extension called "ConfirmButton" that will help you prevent the user from clicking in a button more than once, and it also does it in a very cool and elegant manner.

Another option will be to use JavaScript or better yet, create a custom button control that has a property to be disabled after it is clicked, if you do that, it will be really easy to reuse it in your other applications.

Hope this helps.

Ricardo
+2  A: 

ASP.NET UpdatePanel always honors the last request. If you make a request while one is processing, the first requests gets terminated and the current one is processed. It was designed and built to work this way.

I would disable the button with JavaScript once it has been clicked.

rick schott
+1 for disabling the button after click..
Jakob Gade
...And ensure that you re-enable the button after the processing is complete.
Jacob G
Take a look at the my note if you have time... There's more going on here.
Brian MacKay
Nevermind, I solved it. ;)
Brian MacKay
+1  A: 

In a home-rolled AJAX framework I worked on awhile back, we simply logged the last call in javascript (javascript function call with many parameters) and prevented subsequent calls with identical parameters. It wasn't ideal, but it did the trick in a pinch.

Jacob G
A: 

The link below solved my problem in about half an hour. Just going with a javascript disable (and I tried several different ways...) did not do the trick due to the timing of the updatepanel.

Disabling UpdatePanels While an Asynchronous Postback is in Progress

Brian MacKay
"The link below solved..." Where is the link?
adinas
@adinas: I had a malformed a tag in there, but it looked ok in the preview. Try it now. :)
Brian MacKay
It now works, Thanks.
adinas