Browser[X] button prob.. asp.net

Posted by Susantaown under ASP.NET on 8/19/2009 | Views : 1623 | Status : [Member] | Replies : 1
Hi All

I Want to use one method in Browser [X] button.. but its not working here is code ..

I use this shot of code in Master.aspx page
--------------------------------------------------
<body onunload="signOut();">

<script type="text/javascript" language="javascript">
function signOut()
{
PageMethods.signOut();
}
</script>



<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />


in .cs file the method is
------------------------------
public void signOut()
{
Session["UserName"] = null;
Session["UserName"] = "";
Session.Abandon();
FormsAuthentication.SignOut();
Response.Redirect("~/Logon.aspx");
}


Can any body suggest why its not working for browser [X] button..

the same method working for my Logout Button. but if the user close the browser i want to call this method..

Need a quick help...?

susant




Responses

Posted by: Raja on: 8/19/2009 [Member] Starter

Up
0
Down
You may need to declare signOut method as WebMethod.

[WebMethod]

public void signOut()
{
Session["UserName"] = null;
Session["UserName"] = "";
Session.Abandon();
FormsAuthentication.SignOut();
Response.Redirect("~/Logon.aspx");
}


Look for this article to see how a PageMethod is called.

http://www.dotnetfunda.com/articles/article454.aspx

Thanks

Regards,
Raja, USA

Susantaown, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response