Virtually every asp.net developer has met the situation when a page postback takes quite some time (this is often related to web service calls at back end) and it is required to prevent user from submitting the form twice. The task sounds easy, doesn’t it? Unfortunately there is no easy and straighforward way in ASP.NET to accomplish this.
The main problem is a default ASP.NET postback behaviour when a disabled html button (the techique is – to disable button straight after clicking) cannot submit the form. Other techiques like using html buttons, hidden fields to pass value to the server side and javascript calls to __DoPostback() are pretty cumbersome and far from being elegant.
Luckily I’ve come across the following method which is both elegant and simple:
Code behind:
protected override void OnInit (EventArgs e)
{
// We need this to disable our button when submitting
Form.SubmitDisabledControls = true;
btnSubmit.UseSubmitBehavior = false;
base.OnInit(e);
}
Page source code:
Enjoy!
Related posts:

[...] while ago Evgeny posted an article on how to prevent double clicks on buttons in ASP.Net. This solution was a little code heavy for my [...]