Disable button in post back

Posted by Bravi under ASP.NET category on | Views : 4066
To avoid duplicate data entry and showing status to the user, we can disable the submit button after a click and change its value to Submitting ... In order to do that following code can be used.

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" OnClientClick="this.disabled=true;this.value='Submitting..';" UseSubmitBehavior="false"  />

Click on the button, will disable it and changes text to 'Submitting..' Note that if UseSubmitBehavior will be true then the button will be disabled and its value will be changed to Submitting ... but the form will not be submitted to the server. So its mandatory in this case to keep UseSubmitBehavior as false.

Comments or Responses

Login to post response