title: Clearing a Response in Postback to download text file from Button Click
body: <p>Now... I could do this is a separate page, but i don't want to!</p>
  
  <p>I am trying to create a service which fetches a load of JS files required for a project, compresses them and downloads a single file, but what it does isn't really the issue, the downloading bit is not behaving as expected.</p>
  
  <p>From many examples on here, including:
  <a href="https://stackoverflow.com/questions/898145/in-asp-net-how-to-get-the-browser-to-download-string-content-into-a-file-c">In ASP.NET, how to get the browser to download string content into a file? (C#)</a></p>
  
  <p>I have the (simplified) code:</p>
  
  <pre><code>Sub Download() Handles button.click
      var AllTheScript as string ="blah blah blah"
      Response.Buffer = True
      Response.Clear()
      Response.ClearContent()
      Response.Write(AllTheScript)
      Response.ContentType = "application/text"
      Response.AddHeader("content-disposition", "attachment; filename=myJavascript.js")
      Response.Flush()
  End Sub
  </code></pre>
  
  <p>Obviously, I also have an <code>&lt;asp:button id="button" runat="server"/&gt;</code> element in my page.</p>
  
  <p>When I click this button, it does all the fetch work (not illustrated above) creates the text file and downloads it... excellent...</p>
  
  <p>Except, at the bottom of the JS file it downloads <code>myJavascript.js</code> it has all the markup from the page in which the button was.</p>
  
  <p>I was under the impression that <code>Response.ClearContent()</code> should remove all this?</p>
  
  <p>What am I doing wrong? Or does this have to be a separate page?</p>