473,573 Members | 2,719 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "onmousedow n" event,
not the "onclick" event. It didn't seem to work with the onclick event.
btnSubmit.Attri butes("onmoused *own") = "fIsSubmit=true ;"
btnLogout.Attri butes("onmoused *own") = "fIsSubmit=fals e;"
btnClear.Attrib utes("onmousedo *wn") = "fIsSubmit=fals e;"

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="JavaS cript">
<!--
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(docu ment.Form1.txtV *oucher.value) != '' &&
TrimString(docu ment.Form1.txtH *ackLicense.val ue) != '' &&
TrimString(docu ment.Form1.txtA *mount.value) != '' &&
args.IsValid )
{
// debouce the click (disabling the button doesn't work).
if ( !fSubmit ) {
fSubmit = true; //document.Form1. btnSubmit.dis*a bled =
true;
return true;
}
}
return false;
}
return true;
}
function TrimString(theV alue)
{
// 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(sVal ue);
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 5202
> 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
2631
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 simply run the appropriate command string through a standard "system()" call which is relatively simple. JAVA on the other hand seems to require...
2
3022
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 Name = "DB2 Personal Edition" Product Password = "DB2PE" Version Information = "8.1" Expiry Date ...
0
4231
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 created with code set UTF-8 / codepage 1208. (Note: Running our test application described below on the database host as opposed to a separate client...
2
4656
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 Center: To return a result set from a procedure to the originating application, use the WITH RETURN TO CLIENT clause. When WITH RETURN TO CLIENT is...
8
2730
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 starts objects for all these 25 clients are created and when client connects it should be accepted and will not allow more than 25 clients to connect...
13
28727
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
4436
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
1721
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 createSocketServer($host='192.168.1.34',$port=2222) { $max_clients = 10;
2
4086
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 server machine IP for client and server) please guide me? server : #include <winsock2.h> #include <iostream> #include <stdio.h> #include...
4
9275
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 between you and your client as to what work is included in, or excluded from, a project.In a study done by CA towards end of last year, one third of all...
0
7750
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7674
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7744
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6369
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5559
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5271
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3708
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2170
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1271
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.