Reputation: 93
I'm trying to implement some sort of solution to the 'double submit' problem that occurs when there is a submit button that fires a code routine that takes some time to run.
Unfortunately, with a good number of users still using old internet browsers and some running no-script addons. I cannot use javascript.
Is there a way to disable a button after clicking a button in asp.net?
Upvotes: 1
Views: 602
Reputation: 203848
So it will be impossible to disable the button without some kinda of client side scripting. If you assume that it will be disabled, no matter what kinda of client side script it is, then that's an impossible task.
What you can do is ensure that the operation they're trying to perform won't ever be run more than once per page load.
Lock
block.lock
block and do nothing, or display an error message of some sort.lock
block, and do your operation. Give the session key an appropriate expiration time; it shouldn't need to be more than a handful of minutes. You could even remove the relevant session key at the end of the operation, if it makes sense for it to be repeated at that point.Upvotes: 0
Reputation: 9136
in button click event just write the code
{
//Some Code
button1.Enabled = false;
}
Upvotes: -3
Reputation: 3261
You can start timer on server after each button click and put it in session. On next click you can check timer and apply or decline next user click.
Upvotes: 0
Reputation: 41266
Short story, no.
In your situation, you would need to make some server side code to detect a double post, and then discard the duplicate request.
Upvotes: 1
Reputation: 7233
Since you want to disable the button after the user has clicked (and while your page is still loading) it has to be done on client side. JavaScript is the only client-side language you can use for this.
So make sure that if the user has Javascript disabled (highly unlikely these days), that your end-page can deal with "double submitted" data.
Upvotes: 2