Solved

Prevent Submit Button Clicked Twice.

Posted on 2004-08-20
3
1,135 Views
Last Modified: 2012-06-21
Hi,

How to prevent user to click a submit button more than once?
I've seen some sites disabled the button once it's clicked. Could

somebody tells me how to do that? Or any other solutions?

Thanks in advance,

Hendry
0
Comment
Question by:MiBlg
3 Comments
 
LVL 21

Accepted Solution

by:
tovvenki earned 30 total points
ID: 11850490
Hi,
try this
in the code behind file
private void Page_Load(object sender, System.EventArgs e)
{

     btnSubmit.Attributes.Add("OnClick","javascript:disableButton();");
}

in the aspx file write this
<HTML>
<HEAD>
<title>MyTitle</title>
<script language="javascript">
function disableButton()
{

document.forms[0].SubmitButtton.disabled = true;
document.forms[0].submit();
}              
</script>
</HEAD>

if you still have problem with this technique then have a look at this article
http://www.codeproject.com/aspnet/ClickOnce_Button_Control.asp

Regards,
venki
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 11853249
Another possibility is to set Enabled = false on the submit button, assuming the submit button is a server-side button control.  Do this on it's click event.

private void Button1_Click(object sender, System.EventArgs e)
{
     // code for whatever needs to be accomplished when the button is clicked.
     ... code here.

     // disable this button once the code has executed.
     Button1.Enabled = false;      
}

John
0
 

Assisted Solution

by:rasaraja
rasaraja earned 20 total points
ID: 11854494
Hi jnhorst,
      Sorry to point this out, but your solution won't work. The button_click() event is raised on the server, if the page takes time to submit, there is no way the button can be disabled . It has to be done on the client side, as tovvenki has suggested.

Hendry,
   You can do it the old way, too --

<HTML>
<HEAD>
<title>MyTitle</title>
<script language="javascript">
function disableButton(this)
{

this.disabled = true;
this.submit();
}              
</script>
</HEAD>

!------********-------- Decare the button-------********-------------

<input type=submit onclick="disablebutton(this)">

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now