Rectangle 27 0

c Page Refresh in ASP.NET?


Yes. But because the content type of the response has been changed from "text/html" to "application/octet-stream" there will be no output rendered in the browser. I would also suggest using a handler to serve out the file - e.g. you could pass a Guid on the query string to identify the desired file.

Note
Rectangle 27 0

c Page Refresh in ASP.NET?


Note
Rectangle 27 0

c Page Refresh in ASP.NET?


Gosh, there's an awful lot of wrangling that seems to occur around this issue. The simple HttpHandler solution seems to be the straightforward and proper way to solve this.

Put this code within an HttpHandler and then link to that handler from the original page, passing in whatever information your handler needs.

Note
Rectangle 27 0

c Page Refresh in ASP.NET?


<script type="text/javascript">
   var oldTarget, oldAction;
   function newWindowClick(target) {
      var form = document.forms[0];
      oldTarget = form.target;
      oldAction = form.action;
      form.target = target;

      window.setTimeout(
         "document.forms[0].target=oldTarget;"
         + "document.forms[0].action=oldAction;", 
         200
      );
   }
</script>

<asp:LinkButton runat="server" id="lnkbtnDownload"
  CausesValidation="false" Text="Download" CssClass="buttonstyle" 
  OnClick="lnkbtnDownload_Click"
  OnClientClick="newWindowClick('download');" />

This will cause the postback to occur in a new window, and your existing Response handling will take care of the download. The original window form is restored for future interaction/postbacks.

Note
Rectangle 27 0

c Page Refresh in ASP.NET?


I'd say you can run this code inside an iframe or you can open a popup for triggering the file download. In this case you are overwriting the Response and the page you was expected to get loaded is lost.

So, I would move this code into a dedicated page and implement one of the two solutions mentioned above.

Note