How to prevent multiple form submissions (have a button do two post backs?)

Last post 01-29-2007 3:45 PM by all2neat. 4 replies.

Sort Posts:

  • How to prevent multiple form submissions (have a button do two post backs?)

    01-29-2007, 1:47 PM
    • Loading...
    • all2neat
    • Joined on 12-06-2006, 12:37 AM
    • Baton Rouge, LA
    • Posts 49
    I have a web form with a button which submits the entries of said form into a database via ADO.NET. The first thing the command does is disables the button however because the database sometimes is slow it takes a few seconds for the form to actually post back thus giving the user the ability to submit the form multiple times by quickly pressing the submit button. Is it possible to have a button do some code, do a post back, then do another block of code? Are there better ways to accomplish what I'm looking for? I am using Visual Studio 2005 Pro as my IDE. I have AJAX and the tool kit installed and am using both.
    New Orleans Hornets Season Ticket Holder!
  • Re: How to prevent multiple form submissions (have a button do two post backs?)

    01-29-2007, 2:08 PM
    Answer
    • Loading...
    • mcmcomasp
    • Joined on 03-08-2004, 4:45 PM
    • Toronto
    • Posts 1,349

    have you tried the ClientClick event.  you can use that and the onClick event together,  the client one should fire first.  In there you can put js to disable the button.  Then just re-enable it after you perform your database actions.

     

    hth,

    mcm

  • Re: How to prevent multiple form submissions (have a button do two post backs?)

    01-29-2007, 2:23 PM
    Answer
    • Loading...
    • augustwind
    • Joined on 07-21-2002, 11:16 PM
    • Garland, TX
    • Posts 4,076
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    check out this tip from ASPNet101.com:

    http://aspnet101.com/aspnet101/tips.aspx?id=81

    David Wier
    MVP/MCP/ASPInsider
    ASPNet101.com - where to look first!
    iWrite Pro - doc/rtft to HTML/One Click PDF & much more
  • Re: How to prevent multiple form submissions (have a button do two post backs?)

    01-29-2007, 3:36 PM
    • Loading...
    • all2neat
    • Joined on 12-06-2006, 12:37 AM
    • Baton Rouge, LA
    • Posts 49

    the first answer is getting me close. I use this as the code for the onclientclick.

    OnClientClick

    ="this.value='Please wait...';this.disabled = true;" however when the button gets disabled my OnClick code never runs. If I remove the this.disabled = true part then the form does change the button and submits the data. I am thinking I could make the button invisible instead of disabled. It would accomplish the same thing for me. I'll post my results (probably tomorrow)

     

    Thank you both for your ideas.

    New Orleans Hornets Season Ticket Holder!
  • Re: How to prevent multiple form submissions (have a button do two post backs?)

    01-29-2007, 3:45 PM
    • Loading...
    • all2neat
    • Joined on 12-06-2006, 12:37 AM
    • Baton Rouge, LA
    • Posts 49
    Actually, I got it working about 2 minutes after my last post. The code I added to my asp button is this.

    OnClientClick

    ="this.style.display='none';"

     This makes the button disappear. If there is an error on the form. the button is made visible by the post back. Otherwise it forwards to a page showing their submission. Thank you for your help.

    New Orleans Hornets Season Ticket Holder!
Page 1 of 1 (5 items)
Microsoft Communities
Page view counter