//Here i’m updating the login status of user when user closed the browser.
//Write a method to update the status
protected void Inactive()
{
DAL.Updatestatus(Session["UserName"].ToString(), false);
}
//Event for logout
protected void Button1_Click(object sender, EventArgs e)
{
Inactive();
}
//Javascript method to capture the browser close event.
//If user clicks on browser close document readystate is ‘Complete’ else ‘Loading’
<script type=”text/javascript”>
function abc()
{
var status = document.activeElement;
if(status ==null)
{
document.getElementById(‘<%=Button1.ClientID %>’).click();}
}
</script>
//call the javascript method on page unload.
<body onunload=”abc();” >
Advertisement