title: jQuery dialog doesn't close from code behind after a Response.TransmitFile
body: <p>My problem is that using the quoted aspx page when i call the closing Dialog from Code Behind the dialog doesn't close.
  If i comment the Response Transmit file part of code then the dialog properly close, else the download starts but the dialog remains opened.
  Let me know if you have some suggestions, thanks!</p>
  
  <p>ASPX PAGE:</p>
  
  <pre><code>&lt;%@ Page Async="true" AsyncTimeout="30" Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
      CodeFile="Default.aspx.cs" Inherits="_Default" %&gt;
  
  &lt;%@ Register src="CreateUI.ascx" tagname="CreateUI" tagprefix="uc1" %&gt;
  
  &lt;asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"&gt;
      &lt;%--JQuery--%&gt;
  
      &lt;script src="Scripts/jquery-1.3.2.min.js" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script src="Scripts/jquery-ui-1.7.2.custom.min.js" type="text/javascript"&gt;&lt;/script&gt;
  
      &lt;link href="Styles/jquery-ui-1.10.4.css" rel="stylesheet" type="text/css" /&gt;
  
      &lt;script type="text/javascript"&gt;
          $(document).ready(function () {
              $('#jobDone').dialog({
                  autoOpen: false,
                  draggable: true,
                  title: "Job completed",
                  open: function (type, data) {
                      $(this).parent().appendTo("form");
                  }
              });
          });
  
          function showDialog(id) {
              $(function () {
                  $('#' + id).dialog("open");
                  return false;
              });
          }
  
          function closeDialog(id) {
              $(function () {
                  $('#' + id).dialog("close");
                  return false;
              });
          }
      &lt;/script&gt;
  &lt;/asp:Content&gt;
  
  &lt;asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"&gt;
  
      &lt;!-- ScriptManager to manage UpdatePanel --&gt;
      &lt;asp:ScriptManager ID="mainScriptManager" runat="server"&gt;&lt;/asp:ScriptManager&gt;
  
      &lt;!-- CreateUI Component --&gt;
      &lt;uc1:CreateUI ID="CreateUIForm" runat="server" /&gt;
  
      &lt;!-- Hidden Field to pass data --&gt;
      &lt;asp:Table ID="TableMain" runat="server" CssClass="table"&gt;
          &lt;asp:TableRow ID="TableRow1" runat="server"&gt;
              &lt;asp:TableCell ID="TableCell1" runat="server"&gt;
                  &lt;asp:HiddenField ID="UI_Paths" runat="server" /&gt;
              &lt;/asp:TableCell&gt;
          &lt;/asp:TableRow&gt;
      &lt;/asp:Table&gt;
  
      &lt;!-- div linked to Jquery dialog --&gt;
      &lt;div id='jobDone'&gt;
          &lt;asp:UpdatePanel ID="UpdatePanelDownload" UpdateMode="Conditional" ChildrenAsTriggers="false" runat="server"&gt;
              &lt;ContentTemplate&gt;
                  &lt;asp:Label ID="LabelMessage" runat="server" Text="Operation ended successfully, do you want to download the produced files?&lt;/br&gt;&lt;/br&gt;"&gt;&lt;/asp:Label&gt;
                  &lt;asp:Button ID="ButtonDownload" runat="server" Text="Yes" Width="50px" onclick="ButtonDownload_Click" /&gt;
                  &lt;asp:Button ID="ButtonNo" runat="server" Text="No" Width="50px" OnClientClick="closeDialog('jobDone'); return false;" /&gt;
              &lt;/ContentTemplate&gt;
          &lt;/asp:UpdatePanel&gt;            
      &lt;/div&gt;        
  
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p>CODE BEHIND:</p>
  
  <pre><code>private void DownloadFile(object uiPaths)
  {
      UIGEN config = (UIGEN)System.Configuration.ConfigurationManager.GetSection("UIGENGroup/UIGEN");
      string toPath = config.sharedPath;
      if (!toPath.EndsWith(@"\"))
          toPath += @"\";
  
      string[] fileNamePaths = uiPaths.ToString().Split(new char[] { '*' });
  
      string zipName = toPath + DateTime.Now.ToString().Replace("/", "_").Replace(":", "_").Replace(" ", "_") + ".zip";
      SharpZipLib.CreateZip(zipName, null, fileNamePaths, SharpZipLib.FolderOffset.LastDirOnly);
  
      try
      {
          FileInfo file = new FileInfo(zipName);
  
          Response.Clear();
          Response.ClearHeaders();
          Response.ClearContent();
          Response.AddHeader("Content-Disposition", "attachment; filename=\"" + file.Name + "\"");
          Response.AddHeader("Content-Length", file.Length.ToString());
          Response.ContentType = "application/x-zip-compressed";
          Response.Flush();
          Response.TransmitFile(file.FullName);
          Response.End();
      }
      catch (System.Exception ex)
      {
          //To do ...Manage the error
      }
  
      //Delete zip from Server Shared Folder
      if (File.Exists(zipName))
          File.Delete(zipName);
  }
  
  protected void ButtonDownload_Click(object sender, EventArgs e)
  {
      if (Page.IsValid)
      {
          DownloadFile(UI_Paths.Values);
      }
  
      ScriptManager.RegisterClientScriptBlock(this, this.GetType(), UniqueID, "closeDialog('jobDone');", true);
  }
  </code></pre>