通过客户端在C#/ ASP.NET页面的JavaScript调用启动文件下载? [英] Start file download by client from Javascript call in C#/ASP.NET page?
问题描述
我需要从javascript code启动从ASP.NET网页文件下载。
I need to initiate file download from ASP.NET page from javascript code.
什么是我最好的选择?是否有可能调用web服务这样做,或以某种方式调用C#页的平常事件处理程序?
What would be my best option? Is it possible to call a webservice to do so, or somehow call usual event handler of C# page?
请注意,我会检索大量数据,许多兆字节。
Note that I will retrieve a large amount of data, many megabytes.
推荐答案
您可以使用一个隐藏的IFRAME元素并启动文件下载请求,这给剂量的感觉了AJAX文件下载。
You can use a hidden IFRAME element and initiate a file download request, which dose give the feeling for a AJAX file download.
当文件被下载,你可以做其他的活动窗体上的客户端。
While the file is being downloaded you can do other activity in your form on client side.
是的,你可以调用web服务或ASPX页面或HTTP处理程序,以及在这个网址
Yes you can call a webservice or aspx page or http handler as well in this URL
function dowloadFileJS() {
// Create an IFRAME.
var iframe = document.createElement("iframe");
// Point the IFRAME to GenerateFile
iframe.src = "GenerateFile.aspx?yourQueryString=myQueryString";
// This makes the IFRAME invisible to the user.
iframe.style.display = "none";
// Add the IFRAME to the page. This will trigger a request to GenerateFile now.
document.body.appendChild(iframe);
}
这篇关于通过客户端在C#/ ASP.NET页面的JavaScript调用启动文件下载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!