I have code which successfully writes a PDF file to the response:
JS:
function DownloadPDF() {
ShowLoader();
window.location.href = _appPath + 'export/' + id;
}
C#:
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.Clear();
response.AddHeader("Content-Type", "application/pdf");
response.AddHeader("Content-Disposition", String.Format("attachment; filename=" + filename + ".pdf; size={0}", buffer.Length.ToString()));
response.BinaryWrite(buffer);
response.End();
I am trying to also send a single line of JavaScript back to the client (which is not working):
// the following appears just before the response.End()
response.Write("<script type='text/javascript'>");
response.Write("HideLoader();");
response.Write("</script>");
Probably self-explanatory, but when the user clicks to download the file, I want there to be an AJAX-like loader gif, which then is hidden once the response is complete. How do I achieve something like this?
edit: I tried Page.ClientScript.RegisterStartupScript(GetType(), "hideloader", "HideLoader();", true);
before and after the block of code that writes the file. It doesn't work either.