Disable button after click and is page valid




Disable button after click and is page valid
To avoid multiple submissions, it's a good idea to disable the button after it's clicked and as long as the page is valid.
 
Let's assume your button code is like the below:
  1. <asp:Button ID="btnSubmit" runat="server" Text="Save" OnClick="Save" />  
In the 'Page_Load' secion of your .vb file, make your code look like the below:

  1. Protected Sub Page_Load() 
  2.         If Not Page.IsPostBack Then  
  3.             BindData()   
  4.         End If  
  5.     End Sub  
  6.   
  7.     Private Sub BindData()   
  8.         btnSubmit.Attributes.Add("onclick""javascript: if (Page_ClientValidate()){this.value='Please wait...';this.disabled=true;}" + ClientScript.GetPostBackEventReference(btnSubmit, ""))   
  9.     End Sub  
You can of course change the Please wait... text to display whatever message you want.


4 people like this article, click here to say you like this article too (4)
Send a link to this page via email Send a link to this page