Wednesday, August 12, 2009

Disable multiple postback

How to disable multiple postbacks from a asp.net page (  the easy way, not the best):

1. Use asp.net Button control, check for OnClick and OnClientClick Property

2.OnClientClick you should add a call to the function DisableButtonOnPostBack:

<asp:Button ID="Button1" runat="server" OnClientClick="return Navigate();" onclick="Button1_Click" Text="Button" />

3.And then add the javascript.

<script type="text/javascript">

function DisableButtonOnPostBack()  {

if (!this.disabled) {
              this.disabled = true;
              return true;
          }
          else {
              return false;
          }

}

</script>

No comments: