ASP.net download page
I have a Reports.aspx ASP.NET page that allows users to download excel report files by clicking on several hyperlinks. When a report hyperlink is clicked, I open a new window using the javascript window.open method and navigate off to the download.aspx page. The code-behind for the download page creates a excel file on the fly using openxml(in memory) and send it back to the browser. Here is some code from the download.aspx page:
byte[] outputFileBytes = CreateExcelReport().ToArray();
Response.Clear();
Response.BufferOutput = true;
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", "tempReport.xlsx"));
开发者_如何学JAVA Response.BinaryWrite(outputFileBytes);
Response.Flush();
Response.Close();
Response.End();
My problem : Some of these reports take some time to generate. I would like to display a loading.gif file on my Reports.aspx page, while the download.aspx page is requested. Once the page request is completed, the loading.gif file should be made invisible.
Is there a way to achieve this. Perhaps some kind of event. I have mootools to my disposal.
Thanks
PS. I know that generating reports like this is not ideal, but thats a different story all together...
Preferably move your report generation logic to a ASP handler, as there is no UI involved here.
On you download.aspx page, open the handler in an invisible iframe, and show the loading animation on your download.aspx page
Add an onload event to your frame in download.aspx to remove the loading animation.
Something like this
<html>
<body>
<iframe id='myframe' src='http://www.google.com'></iframe>
<script language='javascript'>
var ifr=document.getElementById('myframe');
ifr.onload=function(){alert('hello');}
</script>
</body>
</html>
精彩评论