Click here to Skip to main content
15,911,707 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to know when browser is closed on client side using C# or in ASP.NET as I want to update the login status of the user in Database.
Hi Friends those links are good but I do not want to use javascript or jQuery I want Solution purly in C# or ASP.NET(using Server side control)

Thanks in Advance :-)
Posted
Updated 15-Mar-11 23:56pm
v2

 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 16-Mar-11 0:22am    
It should solve the problem. My 5.
--SA
Abhinav S 16-Mar-11 0:33am    
Thank you.
Albin Abel 16-Mar-11 2:27am    
Good links. My 5
Hi Friends those links are good but I do not want to use javascript or jQuery I want Solution purly in C# or ASP.NET(using Server side control)

It's impossible - The browser is a client piece of software.

Your server is running your C# code. How is the server ever going to know that the client has done something? It can't subscribe to 'client events', which is exactly what closing the browser is.

Instead, it's up to your design to make the browser inform the server that an event has taken place. *You need to run some code on the client to inform the server*

Your options here are limited. Javascript is the obvious choice, because it's cross browser compatible and you've a fairly high % chance that it's going to be enabled.

A solution I've seen used for this is to have javascript subscribe to the 'onclosing' event on the client, and call a web service in the event handler to tell the server 'I've closed the browser window'
 
Share this answer
 
Comments
Uday Kumar B R 17-Mar-11 6:23am    
I wanted know are there any predefined methods in C# so that I can know when broser is closed
Dylan Morley 17-Mar-11 6:29am    
Didn't you understand "It's impossible"?

You *have* to do this on the client. There is no way to do this server-side in C#
Uday Kumar B R 17-Mar-11 7:19am    
Thank You :-)

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