473,372 Members | 1,104 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,372 software developers and data experts.

Prevent double submit of asp.net v2.0 form

Hi all.

I have a problem in my website in trying to prevent a user from double submitting the form. I am calling a subroutine from my page_load event that passes in the commandbutton that I want to prevent users from being able to click twice. Everything is working great, except for one small detail. When my client-side validation fires, and is invalid, I see the red text that displays the error message, but the problem is that something is "stuck" and I cannot cause a postback for 1 click.. I will give 2 examples of what I mean by this:

1) I press submit and my client-side validation tells me that I need to enter the password, but at this point, I click the cancel button, which should take me to a previous screen, but instead, all it does is get rid of the validation text that tells me to enter the password. When I click cancel AGAIN, it works great.. Basically I have to press cancel twice in this case.

2) This is the real problem I have had with this: After validating a dropdown, the validation errormsg says I need to select a value from the dropdown before submitting. OK, I do this, on a dropdown that has autopostback=true set, but IT DOES NOT POSTBACK. This is very bad because I have logic on the onselectedindexchange event for this dropdown, and it now doesn't fire. Of course, if I re-select another dropdown value at this time, then everything is great, and it postsback just fine.

I hope the code below will be enough information to duplicate, and/or help me determine what I am doing wrong. I can also dumb the code down if need be, so that it only disables the submit button for example. Also, if need be, I can post a small sample asp.net application later that may help you to see the problem.

Here is the code:

Public Sub PreventDoubleSubmit(ByRef cmd As System.Web.UI.WebControls.Button)
Dim sb As New System.Text.StringBuilder

ClientScript.GetPostBackClientHyperlink(cmd, "")

sb.Append("if (typeof(Page_ClientValidate) == 'function') { ")
sb.Append("if (Page_ClientValidate() == false) { return false; }} ")
sb.Append("var outerPane = document.getElementById('FreezePane');")
sb.Append("var innerPane = document.getElementById('InnerFreezePane');")
sb.Append("if (outerPane) outerPane.className = 'FreezePaneOn';")
sb.Append("if (innerPane) innerPane.innerHTML = 'Please wait...';")

cmd.Attributes("onclick") = sb.ToString()
End Sub

It is called from page_load as follows:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub

there is also a couple divs in the html that are needed and referenced by the javascript to basically pop up a 'Please wait' message on successful validation and submit:

<div align="center" id="FreezePane" class="FreezePaneOff">
<div id="InnerFreezePane" class="InnerFreezePane"> </div>

Finally, here are a few css styles to make it look nice:

.FreezePaneOff {
visibility: hidden;
display: none;
position: absolute;
top: -100px;
left: -100px;

.FreezePaneOn {
position: absolute;
top: 0px;
left: 0px;
visibility: visible;
display: block;
width: 100%;
height: 100%;
background-color: #666;
z-index: 999;
padding-top: 20%;

.InnerFreezePane {
text-align: center;
width: 66%;
background-color: #efefef;
color: black;
font-size: large;
border: dashed 2px #111;
padding: 9px;
Mar 27 '07 #1
0 6143

Sign in to post your reply or Sign up for a free account.

Similar topics

by: entoone | last post by:
I have an html form, that has fields and when the submit button is pressed, the information is transferred to a php file. Which then inserts the data into my sql database. How can I go about...
by: G4Gun | last post by:
Hi, I have a form in which I have this link :- < href="javascript:submitform(parameters );"> . In the JavaScript function submitform, there is the code for submitting the form.Thi works fine with...
by: anonieko | last post by:
Scenario: You have a page that is TOO slow to refresh. But it allows partial flushing of html contents. I.e. Submit button already appears but you don't want your users to click on it prematurely...
by: Lloyd Dupont | last post by:
I have a web form with multiple part. I do want the user to click the submit button to post back, so I know which functionality was triggered. unfortunately, when the focus is any text box, if...
by: Anders K. Jacobsen [DK] | last post by:
Hi im building a administraive application (primary) CRUD. But how do i prevent users not to double click on eg a insert button? I would be great the have uniform way to deal with this since I...
by: rmgalante | last post by:
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...
by: Ed Jay | last post by:
On a multi-textbox form, linked to an external js, I use onBlur to call: function chkNum(cellname) { var str = document.getElementById(cellname).value.toString(10); if (str < 28 || str > 36)...
by: APA | last post by:
Why does adding code to the form submit function using the RegisterOnSubmitStatement method prevent the server side event handler for the submit button from firing? This is completely useless. I...
by: PJ6 | last post by:
Is there a way to prevent the double-click event on an element from causing IE6 to select everything? Cancelling the event doesn't work. Paul
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
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...
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...
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...

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.