ASP.NET - Need to update user status when click logout or close browser window?

Asked By avula on 29-Jan-13 02:34 AM
Hi Every one,

I need to update the User status "Y" or "N" in database when he logout , it working fine when i click logout
but what about closing browser..

it should be update the status of user when close the browser also..

please help me..

Thanks you all
RAJESH VEMUNOORI replied to avula on 29-Jan-13 04:05 AM

You could use window.onbeforeunload function in javascript
Hi avula,

Please try this...

window.onbeforeunload = function(e) {
   
// check condition
   
return 'Dialog text here.';
};

following are some links

https://developer.mozilla.org/en-US/docs/DOM/window.onbeforeunload

http://stackoverflow.com/questions/1889404/jquery-ui-dialog-onbeforeunload

Using JQuery

http://www.mkyong.com/jquery/how-to-stop-a-page-from-exit-or-unload-with-jquery/

http://dotnetkicks.com/aspnet/Use_jQuery_to_standardize_window_onbeforeunload_across_browsers

http://www.webhostingtalk.com/showthread.php?t=927093http://dotnetkicks.com/aspnet/Use_jQuery_to_standardize_window_onbeforeunload_across_browsers http://www.webhostingtalk.com/showthread.php?t=927093
avula replied to RAJESH VEMUNOORI on 29-Jan-13 05:03 AM
NO, it is not updating in database..

when loading the page and i have clicked close in browser , so its not updated to "N" in database..still it is in "Y"
please help me

thank you
RAJESH VEMUNOORI replied to avula on 29-Jan-13 10:45 AM
You mean to say update process is in the page which you have closed before load..right!
avula replied to RAJESH VEMUNOORI on 29-Jan-13 11:31 PM
Yes exactly.

RAJESH VEMUNOORI replied to avula on 31-Jan-13 04:05 AM
Hi,

You better call a http handler in the event window.onbeforeunload.. with in the handler you can do what ever you want..you can even update your flag from 'N' to 'Y'.

Let me know if this is helpful..


Regards,
Rajesh.