Click here to Skip to main content
15,915,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
While closing Browser need to call a method in c#. OR need to reset a ISconnected to zero in DB table

What I have tried:

JS 

<pre>    window.onbeforeunload = function (e) {
// Your logic to prepare for 'Stay on this Page' goes here 
if((window.event.clientX<0) || (window.event.clientY<0))
    {
      UpdateLoginPassword();
    }
};



C#

public void UpdateLoginPassword(object sender, EventArgs e)
    {
            //To update Isconnetedflag flag to 0
            Quadra.Suite.Essential.UserManagement.ISYSUserService SYSUserService = serviceUtil.GetServiceProxy<Quadra.Suite.Essential.UserManagement.ISYSUserService>();
            SYSUserService.UpdateIsConnected(Convert.ToInt16(LOGIN_DETAILS.LoginUserID));
    }
Posted
Updated 17-May-17 20:48pm
Comments
F-ES Sitecore 18-May-17 4:20am    
You don't know when the browser is closed, and what if I don't close it but hibernate my machine, or simply leave it open for 3 days? The web is stateless and you should architect your sites so that they obey that and are stateless themselves. You will never know if the user is there or not.

you can do this with ajax that calls a web service or web api function.

<script type="text/javascript">


<pre>if((window.event.clientX<0) || (window.event.clientY<0))
    {
$.ajax({
         type: "POST",
         url: 'YOURWEBSERVICENAMEHERE.asmx/UpdateLoginPassword',
         data: "",
         contentType: "application/json; charset=utf-8",
         dataType: "json",
         success: function (msg) {
              alert('success');
         },
         error: function (e) {
              alert('fail');
         }
       });
    }
};
</script>
 
Share this answer
 
See the first and verified answer.

Source: how to call an ASP.NET c# method using javascript - Stack Overflow
 
Share this answer
 

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