0

I am writing a Web Forms Application in .Net Framework 4.5. In an ASP page, is there any way to check and do some action before closing browser page. For example, sign out or call a function if user clicked "X (close)" button of tab or browser window. Is there any method to handle this exit? (I also prefer having close reason. user closed or error closed etc.)

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
JoshuaJeanThree
  • 1,382
  • 2
  • 22
  • 41
  • Possible duplicate of this question http://stackoverflow.com/questions/2117870/page-unload-event-in-asp-net – Ahmed Masud May 18 '13 at 15:49
  • 1
    @AhmedMasud `Control.Unload` isn't triggered when you close a browser window. So not a dupe. However this question has the answer he's looking for http://stackoverflow.com/q/16584663/1193596 – Amicable Jul 18 '13 at 13:08

1 Answers1

0

There is an Unload event, but if you are to implement something before the page is closed, you should do this on the client side since you cannot make further changes to the response stream when Unload is called. Please refer Page Life Cycle for details.

Jquery Unload is a good choice for that type of controls.

Semih Yagcioglu
  • 4,011
  • 1
  • 26
  • 43