At first I thought you were pulling a Friday funny on me.

But I do see your point, having properly read your post now.

I think, in our case, the web form is a very long way away from the database, 
and after submission we go through a few human workflow steps involving 
assessing and validating the submissions before it gets anywhere near our DB, 
so I might just stick with JavaScript for the moment. Double-submission is more 
of an annoyance than a peril in our situation.

Here's what I've gone with (because I lurve C# and hate JavaScript)

btnSubmit.Attributes.Add("onclick", "this.disabled=true;");

in the form OnLoad.

Dylan.


________________________________
From: [email protected] [mailto:[email protected]] On 
Behalf Of David Connors
Sent: Friday, 30 July 2010 8:44 AM
To: ozDotNet
Subject: Re: ASP.NET 101 - How to prevent double-clicking on a submit button?

On 30 July 2010 08:37, Dylan Tusler 
<[email protected]<mailto:[email protected]>>
 wrote:
We've got an Ajax-ified multi-page form and I want to prevent double-clicking 
on the final page's Submit button. My first thought is just to disable the 
button in its on_Click event handler. Is this a suitable approach?

No. It might give you a perfunctory guard against a double-submission in the UI 
layer but, with the web being what it is, you cannot guarantee it won't be 
submitted twice.

I've looked around a little, trying to see what is the best approach to prevent 
someone from clicking twice (or more) on a submit button, but there seems to be 
a wide variety of methods to choose from, many involving JavaScript, or css, 
and so on. None of them seem simple enough to risk experimenting with.

The approach we always apply is:

 1.  Create a table in your DB, two columns, one being called DoubleSubmitGuard 
(GUID) and the other being DateTimeSubmittedUTC (Date/time).
 2.  At the time you generate the form, roll a new GUID, put it in that table, 
and also embed it in the form.
 3.  As a part of the form submission process, check that DateTimeSubmittedUTC 
is null, then do your normal work, and at the end of the transaction set the 
DateTimeSubmittedUTC to mark the form as submitted.
 4.  Optionally you can display something to the user along the lines of "This 
form has already been submitted" if they click submit twice.

Also disable the submit button as well if you want to improve the user 
experience, but I would not be using the disabling of UI elements to 
effectively implement the integrity if your database.

David.

--
David Connors | [email protected]<mailto:[email protected]> | 
www.codify.com<http://www.codify.com>
Software Engineer
Codify Pty Ltd
Phone: +61 (7) 3210 6268 | Facsimile: +61 (7) 3210 6269 | Mobile: +61 417 189 
363
V-Card: https://www.codify.com/cards/davidconnors
Address Info: https://www.codify.com/contact


-------------------------------------------------------------
To find out more about the Sunshine Coast Regional Council, visit your local 
office at Caloundra, Maroochydore, Nambour or Tewantin or visit us online at 
www.sunshinecoast.qld.gov.au.  If correspondence includes personal information, 
please refer to Council's Privacy Policy at http://www.sunshinecoast.qld.gov.au 
.

This email and any attachments are confidential and only for the use of the 
addressee.  If you have received this email in error you are requested to 
notify the sender by return email or contact council on 1300 00 7272 and are 
prohibited from forwarding, printing, copying or using it in anyway, in whole 
or part. Please note that some council staff utilise Blackberry devices, which 
results in information being transmitted overseas prior to delivery of any 
communication to the device.  In sending an email to Council you are agreeing 
that the content of your email may be transmitted overseas. Any views expressed 
in this email are the author's, except where the email makes it clear 
otherwise. The unauthorised publication of an email and any attachments 
generated for the official functions of council is strictly prohibited. Please 
note that council is subject to the Right to Information Act 2009 (Qld) and 
Information Privacy Act 2009 (Qld).

Reply via email to