title: Start a file download after a Postback
body: <p>In my application I am building a zip file for the User to download for some exported database information. The zip file is created when the user clicks a "generate data" button and I log the request in the database. </p>
  
  <p>On my page, I have a Gridview which shows the download history of the User and also offers them the ability to download the latest generated file for a set period of time. </p>
  
  <p>The issue I'm having is when they click the button, I'd like the page to refresh (thus refreshing the gridview and showing their latest request) and then start the file download for them (IE, bring up the prompt and let them decide whether to open/save/cancel it). </p>
  
  <p>I'm able to start the download on a post back, but my Gridview is not updating before it begins so it doesn't show the newest request in the list. How can I get the gridview to update BEFORE the download prompt starts? </p>
  
  <p>I'm using the following to start the download: </p>
  
  <pre><code>    public void BeginDownload()
      {
          FileDownload download = InventoryService.GetLastThreeFileDownloads(this.EmployeeId).First();
          FileInfo fi = new FileInfo(Server.MapPath(SERVER_DOWNLOAD_PATH) + download.DownloadFileName);
  
          Response.Clear();
          Response.ContentType = "application/zip";
          Response.AppendHeader("Content-Disposition", "attachment; filename=" + fi.Name);
          Response.TransmitFile(fi.FullName);
          Response.Flush();
      }
  </code></pre>
  
  <p>The method is called in the Page_Load event as the last item, if a hidden field is set to true (which I set when they click the button to build the file).</p>
  
  <p>I've also tried doing this through jQuery / AJAX calls to either refresh the page and start the download with little success. I have thought about opening a modal dialog and letting them click a link to start the download and then refresh the page when the modal closes, but that's a last resort if I can't find another solution.</p>
  
  <p>Any help is greatly appreciated!</p>