简体   繁体   中英

C# ASP.NET Detect Download

I am maintaining a website written in C# with ASP.NET. At the bottom of a page is an iframe. When a user clicks a button, the source for that iframe is set with Javascript to a page on the server.

showLoadWidget();
document.getElementById("downloadFrame").src='SdrTrendDownload.aspx';
return false;

That page generates a file and allows the user to download it. Once the download file box pops up, I want to call hideLoadWidget() so the 'Loading Data...' overlay goes away. How do I detect when the download file box pops up?

You can't detect that in addition this get more complicated depending on their security setting for the zone detected for your site

I will suggest that you just wrap the call inside updatepanel and use the partial postback to trigger the download prompt and progress template for displaying the loading widget. Let .net and the browser deal with it.

You can't, much less the browsers (like Chrome) who actually don't pop open a download file dialog. What you should probably do is simply attach to the 'ready' or 'loaded' event on the page and hide the widget when that event occurs.

Tejs is correct. IE 9 doesn't do a modal dialog anymore either. What you can do is set up a download progress watcher and programmatically hide the overlay once the watcher sees data is being sent to the client.

Can you use a hidden HTML form element reporting a DOM event such as onload or onfocus? I set some of these hidden fields in formmail.php from tectite.com, which sends email from a page to a mailbox on the server.

Well, I don't think you can do that. "The Download File Box" is a browser feature. What you should do is call the hideLoadWidget() right after you call the download.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM