title: ASP.NET Ajax: close window after Ajax call?
body: <p>I'm using ASP.NET Ajax. How can I <strong>tell the browser to close the current window</strong> after the server call finishes (server-side code)?</p>
  
  <p>I managed to do this using the ASP.NET Ajax's ScriptManager method "RegisterDataItem" in the server method (inside a button click handler):</p>
  
  <pre><code>sm.RegisterDataItem(ActionLabel, "action:closewindow")
  </code></pre>
  
  <p>and a hidden Label and handling it this way on the client:</p>
  
  <pre><code>function PageLoadingHandler(sender, args)
  {
      var dataItems = args.get_dataItems();
      if (dataItems['ActionLabel'] == 'action:closewindow') {
          window.close()
      }
  }
  Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(PageLoadingHandler);
  </code></pre>
  
  <p>But it feels <strong>dirty</strong>. There must be a more elegant way to do this.</p>
  
  <p>Thanks for any advice.</p>