Using [x] button in Windows forms or Web Applications  
Author Message
Andrew Mercer





PostPosted: Visual C# General, Using [x] button in Windows forms or Web Applications Top

Hi,

Is there a reliable way to catch the Action of a User when they decide to use the [x] button to shut down a Browser.

With Windows Forms its is nice and neat via the Dispose method - here it allows me to do any closing actions as required...

I have tried catching the [x] action in the past using javascript and then calling a Servlet (Previous Java Application I was on) to do the action - however that was not always reliable as the window sometimes closed before the action happened causing an error/exception.

I need to catch the close[x] action of the user and log the logout time, I cannot trust them to always use the Logout button I have provided. I have yet to find a C#/.NET option when searching.

Thanks for any help.

Andrew




Visual C#15  
 
 
Paul Louth





PostPosted: Visual C# General, Using [x] button in Windows forms or Web Applications Top

Use the onunload event on the body of the page. There's no direct C# support for this, but you can call a web-service in the unload event to force the log off:

<html>
<body onunload="alert('here')">

</body>
</html>


 
 
Andrew Mercer





PostPosted: Visual C# General, Using [x] button in Windows forms or Web Applications Top

Thanks,

Very helpful.

Javascript and Java at the time I was using it/trying this a couple of years ago was less reliable.

Andrew