blog.scoreman.net

Archive for June, 2010

JQuery: disable all input controls before postback

Wednesday, June 16th, 2010

If you have very eager users that keeps pushing the submit buttons like a maniac you may want to disable the submit button(s). Here is a script that you can use if you have a UpdatePanel with asynchronous post-backs. The script hooks up to the begin request event and calls a function that finds all submit buttons and disables them.

<asp:UpdatePanel runat="server">
  <contenttemplate>

    <!-- Here goes all input controls -->

    <script type="text/javascript">

      var prm = Sys.WebForms.PageRequestManager.getInstance();
      prm.add_beginRequest(function() {
        disableSubmitButtons();
      });

    </script>

  </contenttemplate>
</asp:UpdatePanel>

<script language="javascript">

  function disableSubmitButtons() {
    $("input[type=submit]").attr("disabled", true);
}

</script>