Does ASP.NET Web Forms prevent a double click submission?
Asked Answered
A

2

6

I'm working on an ASP.NET 4.0 Web Forms project, after a break of about 5 years, and I'm confused about the submit behaviour.

In the click event of a button, I sleep the thread so that I can click the submit button multiple times.

From what I can tell, ASP.NET is preventing the click event being called more than once. Is this true?

BTW: I've turned off javascript for this test.

Aspect answered 24/7, 2012 at 11:10 Comment(2)
possible duplicate of ASP.Net double-click problem & Prevent double-clicking on Button and #11343046Philippa
The problem with those answers is that they talk about implementing a token to determine whether a double submission has taken place. This is what I was about to do until it looked like ASP.NET was preventing it anyway. There is just 1 answer, https://mcmap.net/q/376176/-asp-net-double-click-problem, that indicates that ASP.NET may take care of it for you.Aspect
P
12

"ASP.NET is preventing the click event being called more than once. Is this true?"

No, actually what is happening to you is that your events are blocked by the lock of the session. (What session is on asp.net, is a module on asp.net that can keeps data for each user that visit the site)

So when you make a submit, and the page is running this submit, and then you make a second one before the first one replay, actually the second one is waiting the first to finish and unlock the session.

To make a test and prove that the session is locking your request, turn off the session and try again your test.

relative:
Web app blocked while processing another web app on sharing same session
What perfmon counters are useful for identifying ASP.NET bottlenecks?
Replacing ASP.Net's session entirely
Trying to make Web Method Asynchronous

Predestine answered 24/7, 2012 at 11:14 Comment(3)
I've performed the test and the results are as you say - when session is disabled, I get multiple hits to the event. When session is enabled, it looks like subsequent requests are thrown out, and not queued, if the event is blocked. From this, I assume if I have Session enabled for a page, I don't have to worry about double submits - as long as I, say, disable the button before responding. Is this correct?Aspect
@Aspect Good, I am glad that I understand the real issue :)Predestine
@Aspect Yes the session is help for many synchronize issue like that one. I have made a custom session that is not lock anything and I lock by my left issue like this one. This is the good part, the bad part is that lock all request and this make request that have not relativity to block the one the other... at least make the life easiest at the first months when you start a site.Predestine
L
-1

No, As you are making your main thread sleep it causes the session to get blocked which prevents it from processing any further requests. Hence it gives that effect. If you have an independent task which can be done without web request and response, then you can perform it in separate thread. This will not block your process.

Leis answered 7/5, 2019 at 9:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.