By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,047 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Preventing Multiple submit (Disabling Submit Button Post Click) Solution

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.