Preventing Multiple submit (Disabling Submit Button Post Click) Solution

M

Mark

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=...lsnyder+disable+submit+javascript&sa=N&tab=wg


Mark
 
T

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 ??
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top