Reputation: 3555
Suppose that you have a single page website with a database behind it, and you want to close all open connections to the database in the page_Unload event. Is there any way the user can close the page that doesn't trigger this event?
In other words: can you rely on the page_onUnload Handler to always execute? Assume that the server stays operational (so not something like a server that suddenly powers down while the page is open).
Upvotes: 0
Views: 46
Reputation: 2477
The Page_Unload
event "is called after the page has been fully rendered, sent to the client, and is ready to be discarded". When the user opens the page, and sees it, the event has already been called.
It is NOT called when the user leaves the page or closes the browser!
Please read about the ASP.NET Page Life Cycle
Upvotes: 1