Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a bit column in my users table, I want to update it on timing base, If user didn't logout and close the browser then how can I update the status from true to false please help to find out the solution. I am using c# linq.

hope for a positive response

Thanks
Posted

1 solution

You could find this problem solved in the source code of my next article: MVC Basic Site: Step 4 – jqGrid Integration in MVC 4.0 using AJAX, JSON, jQuery, LINQ, and Serialization[^]

You should look on the next parts:

1. In AccountController the method OnWindowClosing() that is invoked from onBeforeUnload and onKeyDown window events, and used to do user session finalization tasks when the browser window is closing.

2.In the main layout view _Layout.cshtml the javscript section from the bottom of the file:
function onWindowClosing() {
            if (window.event.clientX < 0 || window.event.clientY < 0) {
                $.ajax({
                    type: "POST",
                    url: "/Account/OnWindowClosing"
                });
            }
        };

        function onKeydown(evt) {
            if (evt != undefined && evt.altKey && evt.keyCode == 115) //Alt + F4 
            {
                $.ajax({
                    type: "POST",
                    url: "/Account/OnWindowClosing"
                });
            }
        };

        window.onbeforeunload = onWindowClosing;
        window.document.onkeydown = onKeydown; 
 
Share this answer
 
v2
Comments
Muhammad Aliyan Qureshi 24-Jun-14 4:38am    
It is very helpful but I am using linq to sql not mvc how can I implement it in my application???? can you please help me or any kind of hint regarding my question????
Raul Iloc 24-Jun-14 4:49am    
1.I am also using LINQ in my web application above, but this is not so important!
2.I already answered to you. The main user interface part in in the JavaScript above and you should use it similarly in your web application. The method from the controller is invoked via AJAX call and inside of them the EF is used to set the flag in the database.
Muhammad Aliyan Qureshi 24-Jun-14 4:53am    
Bundles of Thanks for your quick response & support Raul Iloc
Raul Iloc 24-Jun-14 6:44am    
Welcome!

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