How can i determine PostBack value in window.onunload?
<p>In our project we are deleting something after the user left the page. We are using window.unload event for doing this.</p>

<pre><code>window.onunload = function() {
  // delete something
}
</code></pre>

<p>We are generally using buttons, linkbuttons..etc in UpdatePanel so we hadn't needed to check Page.IsPostBack property.</p>

<p>Today we realized that we used some buttons out of UpdatePanel and this situation had produced some errors. After that we decided to change our method, defined a global variable (var _isPostBack = false), at the top of the our page and:</p>

<pre><code>window.onunload = function() {
  if (_isPostBack) {
    _isPostBack = false;
    return;
  }

  // delete something
}
</code></pre>

<p>Altought i set the g_isPostBack in Page_Load, g_isPostBack didn't change. I tried "RegisterClientScriptBlock", "RegisterOnSubmitStatement" and "RegisterStartupScript" methods. Register methods were called before the onunload event but _isPostBack was set after onunload event had triggered...</p>

<pre><code>if (IsPostBack)
{
  Control c = MyClass.GetPostBackControl(this);
  bool inUpdatePanel = ControlParentForUpdatePanel(c);

  if (!inUpdatePanel)
  {
    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), Guid.NewGuid().ToString(), "_isPostBack = true;", true);
  }
}
</code></pre>

<p>Is there anyone to help me?</p>

<p>Thanks...</p>
