title: Closing jquery modal window conditionally from ASP.net code-behind
body: <p>I have an ASP.net page with a link to open a jquery-based modal window (that uses colobox jquery plugin). The content of that window in loaded from another aspx file (it loads an iframe). I want to close that window when the user presses an asp:button and if some condition in my code-behind went well. </p>
  
  <p>I tried many ways to close that window from code-behind like these ways:</p>
  
  <pre><code>Page.RegisterStartupScript("X", @"$(this).dialog('close');");
  
  Page.RegisterStartupScript("X", @"var win = window.open('','_self'); win.close();");
  
  btnDone.Attributes.Add("onclick", @"var win = window.open('','_self'); win.close();");
  
  btnDone.Attributes.Add("onclick", @"window.open('../px/nsk.aspx', '_self', null); window.close(); ");
  
  System.Web.HttpContext.Current.Response.Write("&lt;SCRIPT LANGUAGE='JavaScript'&gt;");
              System.Web.HttpContext.Current.Response.Write("self.close();");
              System.Web.HttpContext.Current.Response.Write("&lt;/SCRIPT&gt;");
  </code></pre>
  
  <p>but non of them can close that modal window. I'm testing on latest version of firefox.
  the code behind can be supposed as sth like this:</p>
  
  <pre><code>    // do some database works
  if (condition)
  {
     // close this modal window
  }
  </code></pre>
  
  <p>I also tried methods from jquery but none of them were a success.
  Can you please telling me how can I close this window?</p>