title: Close a browser window of an ASP.NET and AJAX application
body: <p>What is the best way to close a browser window of an AJAX ASP.NET application after the server-side has been executed.</p>
  
  <p>I found this <a href="https://stackoverflow.com/questions/250450/aspnet-ajax-close-window-after-ajax-call">solution</a>, but it seems a little complex for what I want to accomplish.  Or is this the best way to accomplish my task.</p>
  
  <p><b>UPDATE:</b> I have to close the window after the button is pressed</p>
  
  <p><b>UPDATE 1:</b> I tried the solution from the other SO question, and it did not work for me.</p>
  
  <pre><code>&lt;asp:Button ID="btnMyButton" runat="server" onClick="btnMyButton_Click" /&gt;
  
  protected void btnMyButton_Click(object sender, EventArgs e)
  {
  }
  </code></pre>
  
  <hr>
  
  <p>I used the following code in my page, but the "The webpage you are viewing is trying to close the windows" module window pops up.</p>
  
  <pre><code>if (ScriptManager.GetCurrent(this).IsInAsyncPostBack)
              ScriptManager.RegisterStartupScript(upApproveRequest, typeof(string), "closeWindow", "window.close();", true);
  </code></pre>
  
  <p>Any way to prevent this?</p>