473,396 Members | 2,158 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.

Preventing Multiple submit (Disabling Submit Button Post Click) Solution

This is a solution... Often users want to keep clicking "submit" when
they are waiting for server processing. Most apps these days like to
disable the submit button to prevent this. You can't just disable the
button in the OnClick event in ASP.Net because then the Click event
won't post to the server (because you disabled it). I searched google
groups, and there is a solution to this problem, but I didn't think it
was clean enough and easy to maintain in a large app... so I created
another.

You can add it to any button (and probably any webcontrol...) with one
line of server-side code after you register the script block. I put
the Javascript function itself in a global constant to easily use
throughout the app.

' Code in the ASPX code-behind
Page.RegisterClientScriptBlock("MyScriptBlock",
c_JavaScript_DisableControl)
btnMyButton.Attributes.Add("OnClick", "DisableControl(this);")

' Code in global module
' Javascript function to disable controls
' (usually buttons OnClick)... has to
' have delay (i.e setTimeout) so the click
' event will fire (click event
' won't fire if the button is disabled)
Public Const c_JavaScript_DisableControl As String = "" + _
"<script>" + _
"function DisableControl(control){" + _
"setTimeout('DelayedDisableControl(" + _
"""' + control.id + '"")',10)" + _
"}" + _
"function DelayedDisableControl(controlID){" + _
"document.all[controlID].disabled = true;" + _
"}" + _
"</script>"")"
FYI... the other posted way to do this can be found here:
http://groups.google.com/groups?hl=e...3DN%26tab%3Dwg
Mark
Nov 18 '05 #1
3 13074
This assumes javascript is enabled on the browser. Did you find any server
side methods that would prevent multiple submits? One obvious use is
ecommerce programming where you wish to prevent multiple credit card
submissions (and charges).

"Mark" wrote:
This is a solution... Often users want to keep clicking "submit" when
they are waiting for server processing. Most apps these days like to
disable the submit button to prevent this. You can't just disable the
button in the OnClick event in ASP.Net because then the Click event
won't post to the server (because you disabled it). I searched google
groups, and there is a solution to this problem, but I didn't think it
was clean enough and easy to maintain in a large app... so I created
another.

You can add it to any button (and probably any webcontrol...) with one
line of server-side code after you register the script block. I put
the Javascript function itself in a global constant to easily use
throughout the app.

' Code in the ASPX code-behind
Page.RegisterClientScriptBlock("MyScriptBlock",
c_JavaScript_DisableControl)
btnMyButton.Attributes.Add("OnClick", "DisableControl(this);")

' Code in global module
' Javascript function to disable controls
' (usually buttons OnClick)... has to
' have delay (i.e setTimeout) so the click
' event will fire (click event
' won't fire if the button is disabled)
Public Const c_JavaScript_DisableControl As String = "" + _
"<script>" + _
"function DisableControl(control){" + _
"setTimeout('DelayedDisableControl(" + _
"""' + control.id + '"")',10)" + _
"}" + _
"function DelayedDisableControl(controlID){" + _
"document.all[controlID].disabled = true;" + _
"}" + _
"</script>"")"
FYI... the other posted way to do this can be found here:
http://groups.google.com/groups?hl=e...3DN%26tab%3Dwg
Mark

Nov 19 '05 #2
Here's an example that demonstrates several approaches:
http://www.daveandal.net/books/6744/...one-click.aspx

"Stephen J. Kladich" <St*************@discussions.microsoft.com> wrote in
message news:B6**********************************@microsof t.com...
This assumes javascript is enabled on the browser. Did you find any server
side methods that would prevent multiple submits? One obvious use is
ecommerce programming where you wish to prevent multiple credit card
submissions (and charges).

"Mark" wrote:
This is a solution... Often users want to keep clicking "submit" when
they are waiting for server processing. Most apps these days like to
disable the submit button to prevent this. You can't just disable the
button in the OnClick event in ASP.Net because then the Click event
won't post to the server (because you disabled it). I searched google
groups, and there is a solution to this problem, but I didn't think it
was clean enough and easy to maintain in a large app... so I created
another.

You can add it to any button (and probably any webcontrol...) with one
line of server-side code after you register the script block. I put
the Javascript function itself in a global constant to easily use
throughout the app.

' Code in the ASPX code-behind
Page.RegisterClientScriptBlock("MyScriptBlock",
c_JavaScript_DisableControl)
btnMyButton.Attributes.Add("OnClick", "DisableControl(this);")

' Code in global module
' Javascript function to disable controls
' (usually buttons OnClick)... has to
' have delay (i.e setTimeout) so the click
' event will fire (click event
' won't fire if the button is disabled)
Public Const c_JavaScript_DisableControl As String = "" + _
"<script>" + _
"function DisableControl(control){" + _
"setTimeout('DelayedDisableControl(" + _
"""' + control.id + '"")',10)" + _
"}" + _
"function DelayedDisableControl(controlID){" + _
"document.all[controlID].disabled = true;" + _
"}" + _
"</script>"")"
FYI... the other posted way to do this can be found here:
http://groups.google.com/groups?hl=e...3DN%26tab%3Dwg

Mark

Nov 19 '05 #3
TJS
page reference doesn't allowing viewing of source code

error message says it 's because of browser settings -- what setting would
prevent display of code text ??
Nov 19 '05 #4

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

Similar topics

4
by: shank | last post by:
Visually, the page will look somewhat like a spreadsheet. It could have hundreds of records (rows) displayed. I want to enable the user to edit any one or any number of records and any fields, then...
3
by: shortbackandsides.no | last post by:
I've been having trouble preventing users pressing Enter part way down a form so the incomplete form gets submitted. I came up with a possible solution - the code below seems to work in both...
4
by: Diane Selby | last post by:
Hi- I am developing an ASP.NET application that can take a few seconds to process the request from the user. We are looking for a client-side solution that will prevent users from resubmitting...
5
by: mayur_hirpara | last post by:
Hi, I have been developing web applications for a while now. However, as I was thinking through the architecture I really don't understand the "How server can identify between which buttons has...
6
by: Oleg Konovalov | last post by:
Hi, I have a web application which is (among other things) doing large SQL Insert's, so sometimes it takes a while, user becomes impatient and clicks again (or just does double-click), so the...
5
by: c676228 | last post by:
Hi everyone, my colleagues are thinking about have three insurance plans on one asp page: I simplify the plan as follow: text box:number of people plan1 plan2 plan3
6
by: Oleg Konovalov | last post by:
Hi, I have a Java/JavaScript GUI application where I perform a lot of long DB operations , which takes 5-60 secs to perform. Sometimes user double-clicks the button or just gets impatient and...
4
by: j1dopeman | last post by:
Hi, I'd like to use a button to save and then submit a form. I can set the onlick of the button to mahButton_click or submit, but I can't figure out how to do both. It looks like c# can't...
2
by: chrisp | last post by:
I have an ASP.NET 2 page with a button that causes a credit card transaction to be authorised. The authorisation procedure may take a few seconds and so I want to prevent the user from clicking the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...
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
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...
0
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,...

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.