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