【问题标题】:ASP.NET On Response.Write to iframe completeASP.NET On Response.Write 到 iframe 完成
【发布时间】:2015-02-06 13:28:09
【问题描述】:

我正在用 ASP.NET 开发一个应用程序,旨在创建报表并将它们下载到客户端。我正在使用发布到服务器的 iframe 执行此操作。操作完成后,使用 Response.Write() 将报告下载到客户端。

与此同时,在客户端上,我正在显示一个 GIF 以表明服务器正在生成报告。当报告成功创建并完成写入客户端后,我想相应地更新 iframe,并隐藏 GIF。

有没有办法判断 response.write() 在 iframe 的父页面中是否成功?

家长:

<iframe id="iframe1" src="import-upload.html" width="100%" height="300" onload="loadFrame()" frameborder="0">

function redirect(type) {
        iframe.getElementById('inputType').value = list.options[list.selectedIndex].value;
        iframe.getElementById('inputAction').value = type;

        document.getElementById("divOptionsContainer").style.display = "none";
        document.getElementById("imgLoadingGif").style.display = "";

        iframe.getElementById('frmUpload').submit();
    }

iframe 来源:

<div align="center">
    <form id="frmUpload" action="AjaxFileHandler.aspx" method="POST" enctype="multipart/form-data" target="_self" style="margin-bottom:20px;">
        <input id="fileupload" type="file" name="files[]" />
        <input type="hidden" id="inputAction" name="action"/>
        <input type="hidden" id="inputType" name="type"/>
    </form>

    <button id="btnReport" type="button" onclick="parent.redirect('Report')" style="">Report</button>
    <button id="btnUpload" type="button" onclick="parent.redirect('Import')" style="">Import</button>
</div>

这是我的第一篇文章。如果需要更多信息,请告诉我。提前致谢。

【问题讨论】:

    标签: javascript asp.net iframe


    【解决方案1】:

    可以收听onloadiframe的事件:

    function redirect(type) {
        iframe.getElementById('inputType').value = list.options[list.selectedIndex].value;
        iframe.getElementById('inputAction').value = type;
    
        document.getElementById("divOptionsContainer").style.display = "none";
        document.getElementById("imgLoadingGif").style.display = "";
    
        iframe.onload = function() {
            document.getElementById("divOptionsContainer").style.display = "";
            document.getElementById("imgLoadingGif").style.display = "none";
        }
    
        iframe.getElementById('frmUpload').submit();
    }
    

    【讨论】:

    • 这适用于重定向,但它似乎不适用于 response.write()。
    • 您可以发布来自 POST 请求的响应标头吗?您可以从 Chrome 开发工具的网络标签中复制它们。
    猜你喜欢
    • 2013-05-09
    • 1970-01-01
    • 2014-07-05
    • 1970-01-01
    • 1970-01-01
    • 2014-08-11
    • 2011-02-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多