yadagiri uppari

yadagiri uppari

  • NA
  • 277
  • 189.6k

problem in firing event when browser is closed

Aug 13 2013 5:35 AM
hi...when browser is closing ,server side is not calling..pls check my code...do edit sir,if required
aspx:
<%@ Page Language='C#' AutoEventWireup='true' CodeFile='Default.aspx.cs' Inherits='_Default' %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  
<title>Detect Browser Exit</title>
</head>
<body onunload="HandleClose()">
<script type="text/javascript" language="Javascript">
    function HandleClose() {
        alert("Killing the session on the server!!");
        PageMethods.AbandonSession();
    }
   
</script>
 <form id="form1" runat="server">
 
 <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server" />

</form>
</body>
</html>

codebehind:
  [WebMethod]
    public static void AbandonSession()
    {
        HttpContext.Current.Session.Abandon();
 string strh = "sp_IsHistory";
        SqlParameter param5 = new SqlParameter("@senderid", 1);
        SqlParameter param6 = new SqlParameter("@receiverid", 5);
        SqlHelper.ExecuteNonQuery(CommonSetting.GetConnectionString(true), CommandType.StoredProcedure, strh, param5, param6);

    }

Answers (3)