| « Don't let me be lonely tonight | Microsoft China writes about NCalc » |
Disabled buttons on long postbacks in ASP.NET
Some users don't realize that when a long query is executing, they should not hit a button again. It can sometimes make an application to crash, for instance if it's a delete button.
To prevent this scenario, here is a script that you can embed with every page. It requires jQuery and ASP.NET Ajax.
var delay = 500; // milliseconds
function pageLoad() {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest( function() {
requesting = false;
$(":input[type=submit]").removeAttr('disabled');
});
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(function() {
requesting = true;
setTimeout(function() {
if (!requesting) return;
$(":input[type=submit]").attr('disabled', 'disabled');
}, delay);
});
}