aspx:
html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Detect Browser Exit</title>
</head>
<body>
<script type="text/javascript" language="Javascript">
JavaScript
function TestAJAX11() {
//alert('This is Testing of Close event');
PageMethods.TestAJAX();
}
window.onbeforeunload = function () { TestAJAX11("hello", "hai"); }</script>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server" />
Detect Browser Exit
</form>
</body>
</html>
codebehind:
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
} [ScriptMethod]
[WebMethod]
C#
public static string TestAJAX()
{
string a="hai";
string b = "hello";
string c = a + b;
return c;
}
Sandeep Singh ShekhawatRank #147 · 15.6K pointsPosted Aug 9, 2013, 9:40 PM EDT
Please go through below link to call server side method in JavaScript
http://decoding.wordpress.com/2008/11/14/aspnet-how-to-call-a-server-side-method-from-client-side-javascript/