Home > Asp.net > Disable button after submit in Asp.net

Disable button after submit in Asp.net


Once the user has filled the form details, or did any kind of changes and clicked on submit button, if we want to prevent the duplicate data entry and show other message like “please wait..”‘then we can do this as below:

<asp:Button  runat="server" ID="btnsubmit" Text="Submit"
OnClick="btnsubmit_Click" UseSubmitBehavior="false"
OnClientClick="this.disabled=true;this.value='Please wait..';"   />

For <asp:imagebutton> usesubmitbehavior will not work hence for this:

<asp:ImageButton runat=”server” ID=”btImageButton” 
ImageUrl=”/images/submit.jpeg” OnClick=”btImageButton_Click” 
OnClientClick=”javascript: Submit(this);” />

 <script type=”text/javascript” language=”javascript”>

function Submit(c){
Page_ClientValidate();
if (Page_IsValid){
c.disabled = true
__doPostBack(c.name, ”);
}
return Page_IsValid;
}

</script>

For furhter reference please visit msdn  :  http://bit.ly/1CpMBq
  1. No comments yet.
  1. No trackbacks yet.

Leave a comment