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
    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
     
    Mark, Oct 9, 2004
    #1
    1. Advertising

  2. Mark

    TJS Guest

    Re: Preventing Multiple submit (Disabling Submit Button Post Click) So

    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
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Purvi T
    Replies:
    0
    Views:
    864
    Purvi T
    Oct 19, 2004
  2. Ghafran Abbas
    Replies:
    0
    Views:
    4,247
    Ghafran Abbas
    Oct 12, 2004
  3. Amy
    Replies:
    0
    Views:
    997
  4. chrisp
    Replies:
    2
    Views:
    1,834
    bruce barker
    Oct 11, 2008
  5. Willie
    Replies:
    5
    Views:
    208
    Evertjan.
    Jul 16, 2007
Loading...

Share This Page