yadagiri uppari

yadagiri uppari

  • NA
  • 277
  • 190.6k

how to call code behind method from aspx page

Aug 10 2013 1:14 AM
Hi....actually when browser is closed then event has to be triggered,,,when browser is closing control is going to aspx page but from there i am unable to call code behind method
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">

    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:
 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
 
        }
    }
    [ScriptMethod]
    [WebMethod]
    public static string TestAJAX()
    {
        string a="hai";
        string b = "hello";
        string c = a + b;
        return c;
    }

Answers (1)