Solved

Prevent Submit Button Clicked Twice.

Posted on 2004-08-20
3
1,144 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

730 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