Disable button after click and is page valid
Tuesday 27 July 2010
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:
-
<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:
-
Protected Sub Page_Load()
-
If Not Page.IsPostBack Then
-
BindData()
-
End If
-
End Sub
-
-
Private Sub BindData()
-
btnSubmit.Attributes.Add("onclick", "javascript: if (Page_ClientValidate()){this.value='Please wait...';this.disabled=true;}" + ClientScript.GetPostBackEventReference(btnSubmit, ""))
-
End Sub
You can of course change the Please wait... text to display whatever message you want.
|
(4)
|
|
|