Disable buttons on post back using jquery in .net app

后端 未结 7 2062
悲哀的现实
悲哀的现实 2020-12-20 17:03

I have a asp.net app that I want to disable the buttons as soon as they are clicked in order to prevent multiple submissions. I\'d like to use jquery for this as the site a

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-20 18:05

    You can do it a slightly different way, like this:

    $(function () {
      $("#aspnetForm").submit(function () {
        $('input[type=submit]').click(function() { return false; });
      });
    });
    

    What this does is makes future clicks ineffective, basically making them do nothing. When you disable an input, it also removes the key/value pair from being submitted with the

    , so your server-side action which is triggered by it doesn't work.

    It's worth noting, in jQuery 1.4.3 you'll be able to shorten this down to:

    $(function () {
      $("#aspnetForm").submit(function () {
        $('input[type=submit]').click(false);
      });
    });
    

提交回复
热议问题