Michael Gaigg: Über UI/UX Design


Highlights of Week 29/2011

Posted by Michael Gaigg


Highlights of Week 20/2011

Posted by Michael Gaigg


Highlights of Week 17/2011

Posted by Michael Gaigg


Highlights of Week 14/2010

Posted by Michael Gaigg


How to Disable Button on form submit in .NET

Posted by Michael Gaigg

This problem seems to be almost too obvious to be posted here but it took me quite some time to actually figure it out how to do it correctly - so I'd might just share it with you.

Disabling the submit button helps users comprehend that their action is in process and waiting for a response can be expected. It also prevents them from clicking the same action more than once which could lead to serious troubles (duplicate entries, application exceptions, etc.)


How do I disable a form submit button on a .NET page that does client-side validation?
The problem is that the button cannot simply be disabled because it would not be enabled again if the client-side validation prevents the form from being submitted.



<asp:Button runat="server" ID="btnSubmit" Text="Submit" OnClientClick="SubmitForm(this);" />


function SubmitForm(source) {
ret = true;
if (typeof (Page_ClientValidate) == 'function') {
ret = Page_IsValid;
if (ret) {
source.value = "Processing...";
source.disabled = true;
__doPostBack(source.name, "");
return ret;