Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET how to disable button on submit?

I have forms with payment in ASP.NET site, when user clicks on asp:Button sometime he submits few times. I want to disable this functionality without harming current ASP.NET site ( by that i mean no fancy jQuery, unless it is very basic and will not interfere with ASP.NET built-in validation)

thanks!!!

like image 864
eugeneK Avatar asked Jun 22 '10 12:06

eugeneK


People also ask

How do I disable the submit button?

Enable / Disable submit button 1.1 To disable a submit button, you just need to add a disabled attribute to the submit button. $("#btnSubmit"). attr("disabled", true); 1.2 To enable a disabled button, set the disabled attribute to false, or remove the disabled attribute.

How can stop multiple clicks on submit button in asp net?

(1)you can disable the controls in javascript and then use GetPostBackEventReference( button id) to submit the webpage. (2)You can use Session to store flag to prevent "double posts". Please check out the following article. u can disable the button by JS using clientside onClick event.


1 Answers

You can easily do this on the button in client side:

onClientClick="this.disabled=true;"

You can also use the approach from Muhammad with this:

onClientClick="if(Page_ClientValidate()){this.disabled=true;}"

If this is still not working, you can initiate the postback yourself before disabling the button:

onClientClick="if(Page_ClientValidate()){__doPostBack;this.disabled=true;}"
like image 136
Oded Avatar answered Sep 23 '22 20:09

Oded