Archive

Archive for April, 2009

How to disable button that causes postback in ASP.net

April 30th, 2009

You can disable a button on the client side to prevent multiple clicks by just adding an onClick function that runs on client side. You should check if page has a client side validation script and it passes first. If so, you just disable the button and call postback event.

Here is an example for the button named “btnAddcustomer”. Just paste it into Page_Load.

1
2
Dim strDisable As String = "if (typeof(Page_ClientValidate) == 'function') {if (Page_ClientValidate() == false) { return false; }} this.value = 'Please wait...'; this.disabled = true; " & ClientScript.GetPostBackEventReference(btnAddCustomer, "")
btnAddCustomer.Attributes.Add("onclick", strDisable)

ASP.Net, Programming , , ,