Even using the Post/Redirect/Get method, and including javascript to disable a button after it has been clicked, I am having a problem with users being able to just rapidly hammer a submit button and get multiple form posts in before server side validation can stop it.
Is there any way to stop this? I’ve even tried this method : how to implment click-once submit button in asp.net mvc 2?
And I’ve tried outright blocking the UI with jquery blockUI. I have BOTH client side and server side validation in place, and they work perfectly – but a user smashing the submit button twenty times in under a second just seems to keep breaking it.
Use javascript to wire the
onclickevent to disable the button.If you are already doing that and you can still get multiple form posts, then the problem is a delay between the clicking of the button and the button being disabled, and you must be submitting the form multiple times during this delay.
To fix this, make the
onclickevent first make a call tostopPropagation()to stop the submit event. Then validate that the form is not in submission-blocked state. You can do this by creating a page-scoped javascript variable with a boolean value likecan_submit. Test for can_submit being true before submitting the form. Set thecan_submit = falsewhen the button is disabled, so even if the button is not disabled fast enough, the form will not submit if the value has already been set to false.