title: AJAX / Postback Issue
body: <p>I've been struggling for the whole weekend with unwanted postbacks.</p>
  
  <p>The popup I'm working on has a button that basicaly fires a few stored procedures and then closes the pop up window.
  What I wanted to achieve is to have the same result when people hit the X closing buton on the top right. 
  So, X button = myCloseButton.</p>
  
  <p>For that I've done this.</p>
  
  <p>AJAX.</p>
  
  <pre><code>$(window).unload(function(){
  var dataToSend = { MethodName: 'UpdateR' };
  var options =
      {
          data: dataToSend,
          dataType: 'JSON',
          type: 'POST',
      };
  $.ajax(options);
  });
  </code></pre>
  
  <p>.ASPX.CS</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
      if (!IsPostBack)
      {   #region Ajax methods
                if (Request.Form["MethodName"] == "UpdateR")
                {
                    UpdateRegister();
                    return;
                }
          #endregion
      }
  }
  </code></pre>
  
  <p>And then <code>UpdateRegister()</code> executes the code that I want to execute once people leave the page.</p>
  
  <p>So, the problem comes when people hit another(whatever) control inside the pop up page. The page enters the <code>(!IsPostBack)</code> and the AJAX method. That's understandable since I'm saying on <code>.unload</code> do this and that. (I've tried <code>$(window).bind('beforeunload', function()</code> and it's not working for the desired purpose)</p>
  
  <p>Any idea on "How can I tell the page to difference when it's a closing event like X button or my control, and any other control on the page?" would be much appreciated.</p>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT</strong>. It's not something about serializing the form and comparing before leaving. No, it's about logins and stuff, so even if people open the pop up and close it immediately I need to get that.</p>