Disable a button on first click

  • Thread starter Thread starter Stuart Quinn
  • Start date Start date
S

Stuart Quinn

Is there a way to disable a button to disallow a user to click on it more
than once?

Thanks!
 
Add client-side javascript: onClick="nameOfButton.enabled=false"
 
The solution maily depends on your client's browser capabilities...
If you can ensure that javascript is enabled, then you can add the
following script:

C#:
yourButton.Attributes.Add( "onClick='yourButton.enabled=false;'");

The problem is if your site is public and you cannot ensure that your
clients all have javascript enabled!
In that case, you can only rely on server side code, and you have to
ensure that if 2 posts came from the same client, all but the 1st will
be ignored!
 
jmnobre said:
The solution maily depends on your client's browser capabilities...
If you can ensure that javascript is enabled, then you can add the
following script:

C#:
yourButton.Attributes.Add( "onClick='yourButton.enabled=false;'");

The problem is if your site is public and you cannot ensure that your
clients all have javascript enabled!
In that case, you can only rely on server side code, and you have to
ensure that if 2 posts came from the same client, all but the 1st will
be ignored!

If you also want to disable pressing the Enter key twice, you need
to move the script to the onSubmit event of the form.

Some of the caveats are discussed in a part of this article:
http://msdn.microsoft.com/msdnmag/issues/06/09/CuttingEdge/default.aspx#S3
 
I guess this.enabled = false; will do as well.
(should) save the trouble of obtaining the clientid
 
This will stop multiple submits.
I got this from this newsgroup and always
wanted to thank the author but could not locate the post..


--aspx code--
<script type="text/javascript">
var submitFlag = false;
</script>
--end code--

--Page Load code--
Submit.Attributes.Add("onclick", "javascript:if(submitFlag){return
false;}else{submitFlag=true;return true;}")
--end code--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top