title: Calling a Page Method when the Browser Closes
body: <p>Hi here I'm trying to call a [webmethod] on bodyunload method.</p>
  
  <p>But it is getting fired on page load itself only. How do i prevent it?</p>
  
  <p>Here's the code I am using:</p>
  
  <pre><code>[WebMethod]
  public static void AbandonSession()
  {
      HttpContext.Current.Session.Abandon();
  }
  
  
  &lt;script language="javascript" type="text/javascript"&gt;
  //&lt;![CDATA[
  
  function HandleClose() {
      PageMethods.AbandonSession();
  }
  
  //]]&gt;
  &lt;/script&gt;
  
  &lt;body onunload="HandleClose()"&gt;
  ....
  ....
  ....
  &lt;/body&gt;
  </code></pre>
  
  <p>Thank you,
  Nagu</p>