title: Response object in asp.net
body: <p>I am sure that I am missing something but anyway this is the problem that I am having,</p>
  
  <p>I have a grid which shows records from a table which are not marked as exported....</p>
  
  <p>I have a button by clicking on which a file is created with these records which are not exported.</p>
  
  <p>This file is created on a server and the idea is to let the user get the saveas dialog box to download the file and the grid should rebind and show no records as these records are marked as exported after clicking the above button.</p>
  
  <p>All these happens but the grid does not rebind until the page is refreshed when the file download code is present .</p>
  
  <p>This is my code</p>
  
  <pre><code>protected void btnCreateTxtFile_Click(object sender, EventArgs e)
      {
  
          VoucherData voucher = new VoucherData();
  
          string filename = voucher.CreateVoucherFile(Convert.ToInt16(cboSociety.SelectedValue),    settings.DCOM02Export.ToString(), User.Identity.Name);
  
          BindGrid();
  
          Response.AddHeader("Content-disposition", @"attachment; filename=" + filename);
          Response.ContentType = "application/octet-stream";
  
          Response.WriteFile(settings.DCOM02Export.ToString() + @"\" + filename);
          Response.End();
  
      }
  </code></pre>
  
  <p>So the problem when I comment out this </p>
  
  <pre><code>        Response.AddHeader("Content-disposition", @"attachment; filename=" + filename);
          Response.ContentType = "application/octet-stream";
  
          Response.WriteFile(settings.DCOM02Export.ToString() + @"\" + filename);
          Response.End();
  </code></pre>
  
  <p>everything works fine.But if I dont then the grid does not rebind until the page is refreshed and the calling the BindGrid() method makes no difference.</p>
  
  <p>Can someone please point out where I am going wrong?</p>
  
  <p>Regards,</p>
  
  <p>Sab</p>