Leaving page event
Hi all, I'm currently trying to create a page with the user will be able to create an order form. I would like to add in some codes to generate a message box when the user navigates away from that page. I tried using both "Protected Override Void onUnLoad(EventArgs e)" as well as "void Page_Unload" but both methods seems to execute right after Page_Load, which resulted in the displaying of the message box the moment the page loads. Appreciate if anyone can advise me on this


Bhushan GawaleRank #299 · 8.4K reputationPosted Jan 11, 2015, 7:53 PM EST
Try using onbeforeunload event
http://www.w3schools.com/tags/ev_onbeforeunload.asp
Yi Rong Tan50 reputationPosted Jan 11, 2015, 8:31 PM EST
Bhushan GawaleRank #299 · 8.4K reputationPosted Jan 11, 2015, 9:13 PM EST
In that case - you will need to take some extra efforts and need to add logic in the event which will differentiate refresh and redirect calls, something like this
http://www.anandkanatt.com/how-do-i-detect-browser-window-closed-refreshed/
Yi Rong Tan50 reputationPosted Jan 14, 2015, 3:28 PM EST