C # ASP.NET Page Exit Event?

I was looking for an event that might fire, or a way to find out if the user is leaving the page. Either go to another page or close the page. Is this possible due to events that fire?

+6
source share
3 answers

Not in ASP.NET as such.

You will need to write some external javascript to do this using something like window.onbeforeunload() . Then you will need to make an AJAX call to tell your back end that this event is occurring. Of course, this is not perfect. A browser crash or forced termination will not trigger this event.

+2
source share

Not through server side events. JavaScript is required to detect page exit.

0
source share

On the client side, you can use onunload() (or onbeforeunload() to give "you are sure" that they would be grateful if it meant that they accidentally closed something after writing a long stackoverlow.com message, but would be annoying users in most cases).

On the server side you cannot, although you can force onunload to do something to signal the server.

As a rule, this means that you consider the Internet as a state, and not stateless. Stateless projects work better with stateless protocols such as web pages; the more your application considers each request as unique and independent of previous requests (although, of course, only that this request will depend on how the client dealt with the previous request), your application is more scalable and reliable.

0
source share

All Articles