title: Detecting when FileStreamResult is Complete
body: <p>I have an ASP.NET MVC app. In my view, I have a button that says "Download". When a user clicks this button, the text changes to "Downloading...". My code for this looks like this:</p>
  
  <p><strong>View.cshtml</strong></p>
  
  <pre><code>&lt;button id="myButton" onclick="downloadClick();"&gt;&lt;span&gt;Download&lt;/span&gt;&lt;/button&gt;
  
  function downloadClick() {
    $('#myButton').html('&lt;span&gt;Downloading...&lt;/span&gt;');
    window.location = '/download/latest';      
  }
  </code></pre>
  
  <p>This code successfully downloads a file. The controller action located at <code>/download/latest</code> looks like the following:</p>
  
  <p><strong>MyController.cs</strong></p>
  
  <pre><code>public class MyController {
    public ActionResult DownloadLatest() {
      var someUrl = "https://my-domain.com/files/latest";
      using (var fileClient = new HttpClient())
      {
        var file = await fileClient.GetStreamAsync(fileUrl);
        Response.ClearContent();
        Response.ClearHeaders();
  
        Response.AppendHeader("Content-Disposition", "Attachment; Filename=latest.txt");
  
        return new FileStreamResult(file, "txt");
      }              
    }
  }
  </code></pre>
  
  <p>The file successfully downloads. However, I can't figure out how to restore the button text to just "download" after the response is retrieved. How do I do that?</p>
  
  <p>Thank you!</p>