0

我的应用程序中有一个导出按钮。当我单击该按钮时,它会回传到服务器并生成一个 Excel 文件。

我想在此过程中显示加载 gif,但是当打开/保存对话框显示时,我想隐藏 gif。

问题是我使用 Response.End 来显示文件打开/保存对话框。

有谁知道如何在 Response.End 之后调用客户端函数,或者有人有其他解决方案如何隐藏 gif 并让用户工作?

这是我的一段代码:

     protected void Page_Load(object sender, EventArgs e)
    {
        //starts the loading gif animation.
        btnExport.Attributes.Add("onclick", "setTimeout(\"UpdateImg();\",300);");
    }

    protected void btnExport_Click(object sender, EventArgs e)
    {
        //generates the file
        Response.ContentType = "application/vnd.openxmlformats-  officedocument.spreadsheetml.sheet";
        Response.AddHeader("content-disposition", "attachment;  filename=ExcelDemo.xlsx");
        Response.BinaryWrite(pck.GetAsByteArray());
        Response.Flush();
        //Response.End();
        HttpContext.Current.ApplicationInstance.CompleteRequest(); 

        //HERE I WANT TO STOP THE ANIMATION AND GO BACK TO THE PAGE!
    }

谢谢你,因巴尔。

4

1 回答 1

1

这种方式你不能那样做。

当您开始将数据发送到文件并打开保存对话框时,您的网页失去了控制,您无法再做任何事情,数据全部进入文件保存。

还有什么其他的,在我看来更好,你有什么选择。

您可以使用处理程序 .ashx 来创建和发送文件,并提供指向页面的链接以及制作文件所需的参数。

于 2012-06-10T09:26:46.657 回答