I have a aspx page containing an iframe which shows a pdf ( i have ashx handler to display pdf in iframe), I also have a download button which onclick stream’s a different pdf to the browser as an attachment.
download to browser code: (this is in ashx handler)
byte[] bytes = // get byte array from table
Response.Buffer = false;
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
// [optional]
Response.AddHeader(
"Content-Disposition",
string.Format("attachment; filename={0}", attachmentName)
);
Response.OutputStream.Write(bytes, 0, bytes.Length);
Response.End();
This code works fine however after sending this response to the browser my iframe goes blank and I have to refresh the page in order to see it again. I tried most of the solutions
but none of them is working. iframe behaves fine in chrome & FF.
Note: if i do downloading stuff using asp:hyperlink to my ashx and setting target=”_blank” it works fine in IE but i need some server side processing to do therefore i cant use this method.
While Chrome and FF leave the page there, this does actually make sense.
You are posting back to the server, then clearing your whole output, placing a file in the stream and sending that. Technically I would say IE is right in blanking out the page.
This is assuming your download button is in the iframe?
The solution I would try is putting that download link in another iFrame or have another page that downloads it and when you press a link it opens the new page which just outputs a file. So the window flashes up but then it disappears and a save dialog button appears. However popup blockers might try to stop this.