Solved

Prevent Submit Button Clicked Twice.

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

772 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

12 Experts available now in Live!

Get 1:1 Help Now