Click here to Skip to main content
15,886,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to notify the user to show a popup window when he closes the browser without loggingout.
Posted

You need to get the Window.Closing Event[^] which occurs directly after Close [^]is called, and can be handled to cancel window closure.
C#
public event CancelEventHandler Closing


On this event you can check whether user is logged out or not, if not then cancel the window closure & prevent your window from closing.

Here is reference for How to detect the browser close event in ASP.Net (C#)[^] you may get some help from it.
 
Share this answer
 
Use onbeforeunload event

JavaScript
<script type="text/javascript"> 
window.onbeforeunload = function (evt) { 
  var message = 'Are you sure you want to leave?'; 
  if (typeof evt == 'undefined') { 
    evt = window.event; 
  } 
  if (evt) { 
    evt.returnValue = message; 
  } 
  return message; 
} 
</script> 


Also refer below link:
http://forums.asp.net/p/1153888/1891072.aspx[^]
Detect browser closing through clicks on the [X] button[^]
Window Close Event of Browser[^]
http://mistonline.in/wp/detect-browser-close-event-and-alert-some-messages-using-javascript/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900