title: Closing RadWindow by invoking javascript from server
body: <p>I have a Control that looks like this:</p>
  
  <pre><code>&lt;telerik:RadCodeBlock runat="server"&gt;
      &lt;script type="text/javascript"&gt;
          function refresh() {
              window.$find("&lt;%= RadAjaxManager1.ClientID %&gt;").ajaxRequest("RebindRecommendations");
          }
      &lt;/script&gt;
  &lt;/telerik:RadCodeBlock&gt;
  &lt;telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="AjaxRequest"&gt;
      &lt;AjaxSettings&gt;
          &lt;telerik:AjaxSetting AjaxControlID="RadAjaxManager1"&gt;
              &lt;UpdatedControls&gt;
                  &lt;telerik:AjaxUpdatedControl ControlID="NameOfGrid" /&gt;
              &lt;/UpdatedControls&gt;
          &lt;/telerik:AjaxSetting&gt;
      &lt;/AjaxSettings&gt;
  &lt;/telerik:RadAjaxManager&gt;
  &lt;telerik:RadWindowManager ID="RadWindowManager1" runat="server"&gt;
      &lt;Windows&gt;
          &lt;telerik:RadWindow ID="RadWindow1" runat="server" NavigateUrl="UrlOfPage" OnClientClose="refresh"&gt;&lt;/telerik:RadWindow&gt;
      &lt;/Windows&gt;
  &lt;/telerik:RadWindowManager&gt;
  </code></pre>
  
  <p>Page:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      function closeWindow() {
          self.close();
          return false;
      }
  &lt;/script&gt;
  &lt;!-- form fields here --&gt;
  &lt;telerik:RadButton runat="server" ID="_cancel" Text="Cancel" OnClientClick="closeWindow"&gt;&lt;/telerik:RadButton&gt;
  &lt;telerik:RadButton runat="server" ID="_submit" Text="Submit" OnClientClick="closeWindow" OnClick="DoSomeDataBaseStuff"&gt;&lt;/telerik:RadButton&gt;
  </code></pre>
  
  <p>This works as intended.  My RadWindow is removed and my control's grid refreshes upon hitting either the cancel or submit buttons.  The problem is that the database isn't finished doing its work by that time so the grid refresh doesn't reveal the changes.  I have attempted to switch my implementation of page to look like this:</p>
  
  <p>Page:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      function closeWindow() {
          self.close();
          return false;
      }
  &lt;/script&gt;
  &lt;!-- form fields here --&gt;
  &lt;telerik:RadButton runat="server" ID="_cancel" Text="Cancel" OnClick="CallJavaScriptToKillWindow"&gt;&lt;/telerik:RadButton&gt;
  &lt;telerik:RadButton runat="server" ID="_submit" Text="Submit" OnClick="DoSomeDataBaseStuffAndThenCallJavaScriptToKillWindow"&gt;&lt;/telerik:RadButton&gt;
  </code></pre>
  
  <p>Code Behind eventually calls this after database work completes:</p>
  
  <pre><code>ClientScript.RegisterStartupScript(GetType(), "Key", "closeWindow();", true);
  </code></pre>
  
  <p>I hit my breakpoint in the closeWindow function, but it doesn't have the same behavior (the window doesn't actually close).  I've tried various iterations like:</p>
  
  <pre><code>ClientScript.RegisterStartupScript(GetType(), "Key", "$(document).ready(function() {return closeWindow();});", true);
  </code></pre>
  
  <p>to no avail.  What am I missing?</p>