Hitting the "Submit" button multiple times by mistake

  • Thread starter Thread starter Dominic
  • Start date Start date
D

Dominic

Hi there,

Suppose there is a "Submit" button on a ASP.NET page. Normally, after
a user hits the submit button, the code-behind will insert a row to
the database (or some database operations). Once it is completed,
another page will display.

Assume that the database operation takes a long time to finish (a few
seconds). After the user hits the submit button on the page once,
processing starts. Before the processing is done (and the second page
appears), the user hits the submit button again. Now, my question is

1. Will there be two requests submitted to the server?

2. Will two rows be inserted to the database (if no special checking
is done to prevent this from happening)?

3. What is the best way to prevent this from happening? Can we simply
use client-side script (e.g. javascript) to disable the "Submit"
button once it is hit so that the user cannot hit it the second time?

Is there any better and generic method of preventing this problem?

THanks
Dominic
 
I don't know if it will always happen but there is a good chance that it
will. You could disable the submit button but it will maintain its disabled
state when the page refreshes so you may have to output some client side
code from the code behind to enable the button.
 
Hi Dominic,

Your assumptions for 1 & 2 are correct. The best way to handle this, is by adding some javascript that will disable the button immediately after it has been clicked. Also, Andy Smith from www.metabuilders.com has put together a server control called OneClick (http://www.metabuilders.com/Tools/OneClick.aspx) that will restrict processing twice.

HTH, Matt Hawley, MCAD .NET http://www.eworldui.net Hi there,

Suppose there is a "Submit" button on a ASP.NET page. Normally, after
a user hits the submit button, the code-behind will insert a row to
the database (or some database operations). Once it is completed,
another page will display.

Assume that the database operation takes a long time to finish (a few
seconds). After the user hits the submit button on the page once,
processing starts. Before the processing is done (and the second page
appears), the user hits the submit button again. Now, my question is

1. Will there be two requests submitted to the server?

2. Will two rows be inserted to the database (if no special checking
is done to prevent this from happening)?

3. What is the best way to prevent this from happening? Can we simply
use client-side script (e.g. javascript) to disable the "Submit"
button once it is hit so that the user cannot hit it the second time?

Is there any better and generic method of preventing this problem?

THanks
Dominic

[microsoft.public.dotnet.framework.aspnet]
 
If that should happen, you can just set "Enabled" to true on the button. Thats not a biggie, though.

I don't know if it will always happen but there is a good chance that it
will. You could disable the submit button but it will maintain its disabled
state when the page refreshes so you may have to output some client side
code from the code behind to enable the button.



Dominic said:
Hi there,

Suppose there is a "Submit" button on a ASP.NET page. Normally, after
a user hits the submit button, the code-behind will insert a row to
the database (or some database operations). Once it is completed,
another page will display.

Assume that the database operation takes a long time to finish (a few
seconds). After the user hits the submit button on the page once,
processing starts. Before the processing is done (and the second page
appears), the user hits the submit button again. Now, my question is

1. Will there be two requests submitted to the server?

2. Will two rows be inserted to the database (if no special checking
is done to prevent this from happening)?

3. What is the best way to prevent this from happening? Can we simply
use client-side script (e.g. javascript) to disable the "Submit"
button once it is hit so that the user cannot hit it the second time?

Is there any better and generic method of preventing this problem?

THanks
Dominic



[microsoft.public.dotnet.framework.aspnet]
 
the problem with disabling the submit button, is what does the user do if it
never comes back, becuase the internet never completed the request? you
should at least use a timer to re-enable button. you should add code to
support double post becuase they will happen even if you disable the button,
say the user thinks it took too long, so they refresh the page, and hit
submit again.

-- bruce (sqlwork.com)


Matt Hawley said:
Hi Dominic,

Your assumptions for 1 & 2 are correct. The best way to handle this, is
by adding some javascript that will disable the button immediately after it
has been clicked. Also, Andy Smith from www.metabuilders.com has put
together a server control called OneClick
(http://www.metabuilders.com/Tools/OneClick.aspx) that will restrict
processing twice.
HTH, Matt Hawley, MCAD .NET http://www.eworldui.net Hi there,

Suppose there is a "Submit" button on a ASP.NET page. Normally, after
a user hits the submit button, the code-behind will insert a row to
the database (or some database operations). Once it is completed,
another page will display.

Assume that the database operation takes a long time to finish (a few
seconds). After the user hits the submit button on the page once,
processing starts. Before the processing is done (and the second page
appears), the user hits the submit button again. Now, my question is

1. Will there be two requests submitted to the server?

2. Will two rows be inserted to the database (if no special checking
is done to prevent this from happening)?

3. What is the best way to prevent this from happening? Can we simply
use client-side script (e.g. javascript) to disable the "Submit"
button once it is hit so that the user cannot hit it the second time?

Is there any better and generic method of preventing this problem?

THanks
Dominic

[microsoft.public.dotnet.framework.aspnet]
 
bruce said:
the problem with disabling the submit button, is what does the user
do if it never comes back, becuase the internet never completed the
request? you should at least use a timer to re-enable button. you
should add code to support double post becuase they will happen even
if you disable the button, say the user thinks it took too long, so
they refresh the page, and hit submit again.

And don't even bother implementing in on the client-side until you have a
server-side solution (unless you can be sure that your users will never be
able to disable client-side scripting).

A typical server-side solution for this is to add a special form token (e.g.
some random number) to each web form as a hidden field and store the last
issued token in the session. If the user submits a form and the value of the
submitted token matches the value of the token that is stored in the
session, the form submit is permitted, otherwise it is rejected.

Cheers,
 

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

Ask a Question

Back
Top