Solved

Prevent Submit Button Clicked Twice.

Posted on 2004-08-20
3
1,149 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

688 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