473,396 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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.

<SCRIPT LANGUAGE="JavaScript">
<!--
var fSubmit = false; // This flag is the debounce flag
var fIsSubmit = false; // This flag gets set or cleared by the
onmousedown events
function Init()
{
document.Form1.txtVoucher.focu*s();
// 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 =
true;
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;
}
else
{
var dValue = parseFloat(sValue);
if ( dValue < 1 || dValue > 500 )
args.IsValid = false;
else
args.IsValid = true;
}
}
// -->
</script>

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
browsers.

Nov 19 '05 #1
1 5179
> 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>
-Darrel
Nov 19 '05 #2

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

Similar topics

1
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...
2
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...
0
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...
2
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...
8
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...
13
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
14
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 {
0
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...
2
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...
4
MMcCarthy
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.