472,358 Members | 1,937 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,358 software developers and data experts.

Client-Side Validation and Double-Click Problem

I have written an ASP.Net application that uses the standard
client-side and server-side validation for various fields on the form.
Some of the customers that use the form report symptoms that appear to
be the result of double-clicking the submit button on the form.

The form has three ASP:Button tags, each of which gets translated into
INPUT TYPE="SUBMIT" HTML elements. One submits the form's data. One
logs the user out. And the other clears the form.

I tried to disable the Submit button in the form's onsubmit event, but
that event is used by the client-side validation. Also, I found that it
was difficult to detect which button was clicked on the form. Finally,
disabling the Submit button made the server process ignore the
btnSubmit_Click event. This technique worked with ASP applications, but
doesn't work with ASP.Net applications.

I had to implement a different solution to solve these problems.

1. First, I added attributes to each button on the form in the
Page_Load event. I implemented a handler for the "onmousedown" event,
not the "onclick" event. It didn't seem to work with the onclick event.
btnSubmit.Attributes("onmoused*own") = "fIsSubmit=true;"
btnLogout.Attributes("onmoused*own") = "fIsSubmit=false;"
btnClear.Attributes("onmousedo*wn") = "fIsSubmit=false;"

2. Then, I added Javascript to the HTML portion of the page as follows.
I had to override the default client-side onsubmit event handler.
Standard validation still works when tabbing from field to field.

var fSubmit = false; // This flag is the debounce flag
var fIsSubmit = false; // This flag gets set or cleared by the
onmousedown events
function Init()
// Override the default submit routine that ASP.Net uses.
document.Form1.onsubmit = OnSubmit;

// This routine does client-side validation.

function OnSubmit() {
// Was it the submit button?
if ( fIsSubmit )
// Added client-side validation to debounce the button, btnSubmit
// Call the same client validation method to validate the number
var args = new Object();
args.Value = document.Form1.txtAmount.value*;
args.IsValid = false;
ValidateAmount(document.Form1, args);

// Make sure the other form values are ok too
if ( TrimString(document.Form1.txtV*oucher.value) != '' &&
TrimString(document.Form1.txtH*ackLicense.value) != '' &&
TrimString(document.Form1.txtA*mount.value) != '' &&
args.IsValid )
// debouce the click (disabling the button doesn't work).
if ( !fSubmit ) {
fSubmit = true; //document.Form1.btnSubmit.dis*abled =
return true;
return false;
return true;
function TrimString(theValue)
// Trim logic removed for brevity
// This is the same function that the client-side validation uses
// for the numeric fields in the form.

function ValidateAmount(source, args)
var sValue = TrimString(args.Value).toStrin*g();
sValue = sValue.replace(/[\$,]/g, '');
if (isNaN(sValue))
args.IsValid = false;
var dValue = parseFloat(sValue);
if ( dValue < 1 || dValue > 500 )
args.IsValid = false;
args.IsValid = true;
// -->

Not as easy as I thought it would be. The real question is, why does
the double-click cause the form to submit twice, but only on some

Nov 19 '05 #1
1 5102
> I tried to disable the Submit button in the form's onsubmit event

Not sure if this helps, but what I have done in the pass is instead of
disabling it, just hiding it.

So, I'd have something like this (pseudo code for the javascript):

<div><button onclick="set this div to display:none, set the other one to
display: block"></div>
<div display: none>Updating database...</div>
Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: ian maclure | last post by:
I'm writing a client-server app. Client controls Server which in turn configures and controls a bunch of hardware. I want to be able to start the server from my client. Now in C/C++ one could...
by: Raquel | last post by:
How do I know whether the 'runtime client' and the 'application development client' are installed on my machine? When I issue the command "db2licm -l", it gives the following output: Product...
by: Tim Northrup | last post by:
Help! We have DB2 V7.2 (fixpak 12) installed on Windows2003 Server, and the latest V7.2 client installed on another system. The DB2CODEPAGE on all systems is set to 1208, and the database was...
by: Rhino | last post by:
I am trying to verify that I correctly understand something I saw in the DB2 Information Center. I am running DB2 Personal Edition V8.2.1 on Windows. I came across the following in the Info...
by: Ankit Aneja | last post by:
i am doing here some some socket-client work in C# windows service it is working fine for multiple clients now i want to limit these multiple clients to 25 for example i want that when service...
by: Sandeep Singh | last post by:
I am making socket client application in C# how can i get ip address of client who has connected to server
by: Ankit Aneja | last post by:
The code of classes given below is for server to which clients connect i want to get ip address of client which has connected pls help how can i get //listen class public class listen {
by: khu84 | last post by:
Here is client server very simple code, seems to work with telnet but with with web client code gives blank output. Following is the server code:- <?php function...
by: nsaffary | last post by:
hi I hava a client/server program that run correctly when i run it in one computer(local) but when I run client on a one computer and run server run on another, connection does not stablish.(I set...
by: MMcCarthy | last post by:
http://bytes.com/images/howtos/projectscope_blocks.jpgAs a freelance IT consultant for over 10 years, Iíve come to appreciate well defined project scopes. A project scope is a common understanding...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.