Andrew Bezzub
Andrew Bezzub

Reputation: 16032

Best way to disable all submit buttons after postback

I'm trying to write code that will disable submit button (or all submit buttons) on the page to avoid double postback.

I thought of generating my own postback javascript function (and inject postback javascript using GetPostbackEventReference) but maybe there are some better ways to do this? Or maybe there is some other way to avoid double postbacks?

Update:

I also want to figure out the best place to call javascript, e.g. if I call following script in the onclick button handler then button's server click event won't be wired up.

$('input[type=submit]').attr('disabled', 'disabled')

Upvotes: 3

Views: 3142

Answers (3)

Chris Conway
Chris Conway

Reputation: 16519

How about this:

$('input[type=button]').click(function() {
    $('input[type=button]').each(function() {
        $(this).attr('disabled', 'disabled')
    });
});

Anytime any button is clicked, every button on the form becomes disabled.

Upvotes: 0

Shawn
Shawn

Reputation: 7365

http://greatwebguy.com/programming/dom/prevent-double-submit-with-jquery/

This should help you

   1. $('form').submit(function(){  
   2.     $(':submit', this).click(function() {  
   3.         return false;  
   4.     });  
   5. });  

Upvotes: 4

Chris Broadfoot
Chris Broadfoot

Reputation: 5112

jQuery:

$('input[type=submit]').attr('disabled', 'disabled')

Otherwise, iterate through all document.getElementByTagName('input')

May be best to do this only for child nodes of the form that was submitted, though?

Upvotes: 2

Related Questions