开发者

Double/Repeated Click on a HTML Button

Our application is using ASP.net MVC and we have a question on what happens in the below scenario.

We have a "button" 开发者_开发技巧which makes a payment and after making a payment we have a session variable which marks "PaymentSubmitted" to True. This session variable will be used to do different stuff based on it's value.

Now I would like to have your inputs in deciding what happens if the user clicks on that "button" twice.

Will the second request (generated from second click of the finish button) wait till the first request is executed ? Or will the second request will move on without worrying much on where is the first request.

note: we refrain from using any client side scripting.


I'm assuming the button click is a "submit" on a form.

Once the button is clicked, a second request WILL get posted. Just imagine, you hit the refresh on your browser on any given page 20 times, those 20 requests are going to be sent to your web server and will be handled in the order that they are received.

You should be able to check the session variable on the subsequent click if you've set it early enough - but this is definitly not safe.

The better approach would be to use JavaScript or post to a different page so that the button is not able to be clicked again while taking payment.


It would be possible to identify the operation (the product buy or whatever it is being payed)? In that case you can mark an operation as "in progress" after clicking the first time. When your server receives a petition, the first thing would be to check the status of the operation, if is "in progress" the server wouldn't start another transaction.

In any case is good to have some client side blocking feature (disabling the button, a modal window with the typical wait message, etc...), mainly for the user, so they have the feedback that "something is going on". But of course not relaying only in that blocking feature, because anything that is client side is susceptible to be altered.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜