Re-submitting click action event problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kpeeroo
    New Member
    • Sep 2008
    • 12

    Re-submitting click action event problem

    Hi all,

    I have a problem with my form i created. When I click the submit button, everything works fine, all data are committed to database but if the user happens to click the submit again, the following exception occurs: Any idea?
    I have cleared all my parameters for the insert command.

    A first chance exception of type 'System.FormatE xception' occurred in System.Data.dll
    standby being added
    4
    4
    at System.Data.Pro viderBase.DbCon nectionInternal .OpenConnection (DbConnection outerConnection , DbConnectionFac tory connectionFacto ry)
    at System.Data.Sql Client.SqlConne ction.Open()
    at WindowsApplicat ion1.Form1.AddC ompanyStandby() in C:\Documents and Settings\Root\M y Documents\Visua l Studio 2008\Projects\W indowsApplicati on1\WindowsAppl ication1\Form2. vb:line 305
    0
    A first chance exception of type 'System.Invalid OperationExcept ion' occurred in System.Data.dll
    at System.Data.Pro viderBase.DbCon nectionInternal .OpenConnection (DbConnection outerConnection , DbConnectionFac tory connectionFacto ry)
    at System.Data.Sql Client.SqlConne ction.Open()
    at WindowsApplicat ion1.Form1.AddC lientStandbyOve rtime() in C:\Documents and Settings\Root\M y Documents\Visua l Studio 2008\Projects\W indowsApplicati on1\WindowsAppl ication1\Form2. vb:line 120
    A first chance exception of type 'System.Invalid OperationExcept ion' occurred in System.Data.dll
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    A FormatException is thrown in the case when the format of an argument doesn't meet the parameter specifications of the invoked method.

    Check to make sure that you are properly opening your database connection and that you are providing it with the correct information the second time you submit the data.

    -Frinny

    Comment

    • balabaster
      Recognized Expert Contributor
      • Mar 2007
      • 798

      #3
      First chance exceptions can be a pain, but they're mostly cosmetic. Wrap the submit functionality in a try{} catch{} if the exception thrown is anything other than a first chance exception then handle it otherwise generally speaking, it can be ignored.

      My initial gut feeling in cases where following the same submit process twice causes an exception is that the submit uses the current open connection which is then closed and disposed. If the submit button is clicked again, it attempts to continue the same process - except this time, the connection doesn't exist - thus causing your exception. Of course, the first time, the connection already existed and was in an open state... the second time, the connection was killed by the submit process the first time around... and thus, your error occurs.

      If we could see the code relevant to the process, it would be helpful in deducing the cause of your exception...

      Comment

      • kpeeroo
        New Member
        • Sep 2008
        • 12

        #4
        Thanks guys

        Yes I surrounded the code of my submit portion with try catch clause and I found out the error. There was one of my text boxes which was not supplying the correct format in which the method was expecting it to be thus raising that exception. But initially, as i dont have much experience in .NET I thought we needed some other piece of code to allow double submitting actions!

        Continuing the discussion, how then would you guys prevent the user from submitting the same data twice to the database by clicking submit button twice? Am using an application form not web form. any suggestions? cheers...

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          Originally posted by kpeeroo
          Thanks guys

          Yes I surrounded the code of my submit portion with try catch clause and I found out the error. There was one of my text boxes which was not supplying the correct format in which the method was expecting it to be thus raising that exception. But initially, as i dont have much experience in .NET I thought we needed some other piece of code to allow double submitting actions!

          Continuing the discussion, how then would you guys prevent the user from submitting the same data twice to the database by clicking submit button twice? Am using an application form not web form. any suggestions? cheers...
          You can disable the submit button using JavaScript once the content has been submitted. This will prevent them from submitting the data while it's being processed. Be aware that once the page posts back to the browser the button will be recreated, therefore it will no longer be disabled. If you want to permanently disable the button (for the time of the usage) you'll have to also disable the button in your server side code (set a flag indicating that it should remain disabled).

          There are a a few peculiarities when disabling buttons through JavaScript though. ASP is automatically configured to ignore any disabled content, and so your button will not actually work once it's disabled. There is a property that allows you to submit disabled input though....I just can't remember it off the top of my head.

          The trend these days is to place a <div> on top of your content once the page is submitted (css opacity set to let the content show through). This will disable all of the content (including DropDownLists etc) because everything will be behind the <div>... it also lets you display a message saying the data's being processed. This also has to be done using JavaScript.

          -Frinny

          Comment

          Working...