Preventing Multiple submit (Disabling Submit Button Post Click) Solution

Discussion in 'ASP .Net' started by Mark, Oct 9, 2004.

  1. Mark

    Mark Guest

    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

    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
    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(" + _
    """' + + '"")',10)" + _
    "}" + _
    "function DelayedDisableControl(controlID){" + _
    "document.all[controlID].disabled = true;" + _
    "}" + _

    FYI... the other posted way to do this can be found here:

    Mark, Oct 9, 2004
    1. Advertisements

  2. Mark

    TJS Guest

    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 ??
    TJS, Dec 13, 2004
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.