title: Enable button after writing file to response
body: <p>There is many similar questions but there is still no clear answer that is solving the problem taking some action after writing some stream to response.</p>
  
  <p>I have a following situation:</p>
  
  <p>On button click I am generating some excel file that I am going to write to response allowing user to download generated file. Imidietly after clicking the button, I am disabling it, to prevent double clicking this button. In Page-Load event handler I have following code:</p>
  
  <pre><code> GenerateBTN.Attributes.Add("onclick", "this.disabled=true;" + ClientScript.GetPostBackEventReference(GenerateBTN, "").ToString());
  </code></pre>
  
  <p>After Page_Load eventhandler, GenerateBTN_Click handler executes the code needed for generating the file and at the end of this method (handler) I am response writing generated file with following code:</p>
  
  <pre><code>Response.Clear();
  Response.ContentType = "application/octet-stream";                
  Response.AddHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
  Response.WriteFile(@"C:\Reports\" + filename);
  Response.End();    
  </code></pre>
  
  <p>The Save As dialog appears and user can download the generated file, but the problem is that the disabled GenerateBTN remains disabled. How to enable it afer Writing generated file to response? I understand that afer clearing current response I can not continue with the initial Response, but is there any way to solve this problem?</p>