简体   繁体   English

在asp.net中的Response.End()之后隐藏模态窗口

[英]Hide modal window after Response.End() in asp.net

I have a button who does the following: 我有一个按钮执行以下操作:

Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.csv");
Response.Charset = "";
Response.ContentType = "application/text";
//my content is created
Response.Output.Write(sb.ToString());
Response.Flush();
Response.End();

This is my button definition: 这是我的按钮定义:

<asp:Button ID="Button1" runat="server" onclick="Excel_Click" Text="Export to Csv" onclientclick="ShowModal();"/>

As you can see I call a javascript function, who does the following: 如您所见,我调用了一个javascript函数,该函数执行以下操作:

function ShowModal() {
        var divmodal = document.getElementById("divModal");

        divmodal.style.display = '';
    }

ie shows a modal window with the label "Loading" My problem is when I download the file I get the csv generated but after that my modal window still appears, that's because the page isn't being refreshed 即显示一个带有标签“加载”的模态窗口我的问题是当我下载文件时我得到了生成的csv但之后我的模态窗口仍然出现,那是因为页面没有被刷新

Is there anything I can do? 有什么我能做的吗?

Thanks in advance 提前致谢

The short answer is that you can not do that. 简短的回答是你不能这样做。

After your post back with the button the page that you are is waiting a new content to load. 使用按钮回发后,您所在的页面正在等待加载新内容。 At this moment you do not have any control to the current page dom from the code behind, eg send them a javascript code to execute. 此时您无法从后面的代码对当前页面dom进行任何控制,例如发送一个javascript代码来执行。

Even if you do send a full page back, then its a new full page. 即使您确实发送了整页,然后是一个新的整页。

You can make some other trick, eg use a handler to download the file and a link, or use ajax to send the command, and again return with a link to a handler - but that way, with a full post back, you can not do that. 你可以做一些其他的技巧,例如使用处理程序下载文件和链接,或使用ajax发送命令,然后再返回一个处理程序的链接 - 但是这样,有一个完整的帖子回来,你不能去做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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