Click here to Skip to main content
14,865,447 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to update the field STATUS in the users table from ONLINE to OFFLINE so that the current online uer list is accurate.
I am using visual studio 2010, aspnet 4.0 version
I have a LOG OFF button that does this but many users click the CLOSE (x) button on the browser to close the forum instead of the LOG OFF button thus they are still ONLINE ain the database and on the forum to other users.

Is there any ASP code that performs a database update when the browser is closed uising the (x) at the top right ?

Much appreciated.

Ashok Luhach

Thanks in advance
Posted
Updated 23-Mar-13 0:51am
v2

1 solution

Hello Ashok,

You can use code similar to one shown below.
HTML
$(document.ready(function() {
    $(window).bind('beforeunload', function() {
        $.ajax({
            url: "logout.aspx",
        });
    });
});

Please note that this snippet makes use of JQuery so your page needs to have a reference to JQuery library.

Regards,
   
v2
Comments
ashok luhach 23-Mar-13 7:26am
   
But where this function call in page and what code write on logout.aspx page to update status of user
Prasad Khandekar 23-Mar-13 7:37am
   
I have updated the code to automatically register the callback on page load.
ashok luhach 25-Mar-13 1:22am
   
sorry sir i cannot understand your answer please give me example with source code and cs code in brief
Prasad Khandekar 25-Mar-13 3:33am
   
Hello Ashok,

Download jquery-1.9.1-min.js from http://jquery.com. Copy it to js or scripts folder of your website. In your page add a reference to jquery-1.9.1-min.js file as shown below assuming that this file exists in js folder of your website.

<:script type="text/javascript" src="js/jquery-1.9.1-min.js"><script>

Add following code block between the <head></head> tags of your page.

<script type="text/javascript">
$(document.ready(function() {
$(window).bind('beforeunload', function() {
$.ajax({
url: "logout.aspx",
});
});
});
</script>

Don't forget to change the logout url in above script block.

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