views:

51

answers:

1

Hi

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"));
    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...

A: 

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'&gt;&lt;/iframe&gt;
<script language='javascript'>
var ifr=document.getElementById('myframe');
ifr.onload=function(){alert('hello');}
</script>
</body>
</html>
Midhat
Set your frame src to your http handler or page. Set is height and width to 0. instead of alert hello, write the code to hide your "loading" element
Midhat
I am quite new to asp.net, what exactly do you mean by handler? Also, the iframe onload does not fire when a download occurs. It only fires when requesting a web site like google in your example.
MegaByte
a handler is just a code file (with .ashx extension) that is used for processing a request without explicitly having a UI (Yes you can output html tags in your response, but thats not the point of writing handler). If you are familiar with J2EE, think of it like a servlet. If you use a handler, you can skip the whole new window all togather, and let the user's browser take over the progress presentation
Midhat
Like I mentioned in my first comment, the onload event of the iframe does not fire when its src points to the asp handler. Any other ideas?
MegaByte