title: I have a typical two file ASP.NET web page (aspx and aspx.cs) where a message variable is not updated after a Response.OutputStream.Write
body: <p>I have a message variable I am using to send feedback to the page on submit and on button clicks on errors etc..
  It all works fine except any changes to the message variable after I stream a xlsx file out to browser are not updated.</p>
  <p>After a Response.OutputStream.Write messages are not updated.</p>
  <p>See the comments in the code below.
  All other places I update the Msg variable the original html page is updated but not after streaming the xlsx file.
  How can a get a message back to the html page after the stream?</p>
  <pre><code>&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; validateRequest=&quot;true&quot; CodeFile=&quot;file1.aspx.cs&quot; Inherits=&quot;Select&quot; %&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta charset=&quot;utf-8&quot;&gt;
  &lt;/head&gt;
      &lt;body&gt;
          &lt;%=Msg%&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  
      protected void GetLeads_Click(object sender, EventArgs e)
      {
          Msg =&quot;&quot;;
          string scans = GetScans();
              using (ExcelPackage excelPackage = new ExcelPackage())
              {
              string sql = &quot;SELECT * from table1 where rec in (&quot;+scans+&quot;);&quot;;
              DataTable dt = loadExternalDataSet(sql);
              
              if (dt.Rows.Count &gt; 0)
                {
                  ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.Add(&quot;Sheet 1&quot;);
                  worksheet.Cells[&quot;A1&quot;].LoadFromDataTable(dt, true);
  
                  byte[] bin = excelPackage.GetAsByteArray();
  
                  Response.ClearHeaders();
                  Response.Clear();
                  Response.Buffer = true;
  
                  Response.ContentType = &quot;application/vnd.openxmlformats-officedocument.spreadsheetml.sheet&quot;;
                  Response.AddHeader(&quot;content-length&quot;, bin.Length.ToString());
                  Response.AddHeader(&quot;content-disposition&quot;, &quot;attachment; filename=\&quot;Leads.xlsx\&quot;&quot;);
                  Response.OutputStream.Write(bin, 0, bin.Length);
  
                  Response.Flush();
                  HttpContext.Current.ApplicationInstance.CompleteRequest();  
                  
                  // This message never displays 
                      Msg = &quot;The file was sent to your browser&quot;;          
             
              }
              else
              {
                      
                      // This message displays OK 
                      Msg = &quot;&lt;span style='color:red;'&gt;The barcode scan data is invalid.&lt;br&gt;Try entering it again.&lt;/span&gt;&lt;br&gt;&quot;;    
         
          }
              }
          }
      }
  </code></pre>