【发布时间】:2016-08-23 12:25:36
【问题描述】:
我开发了一个页面,当用户单击按钮时,在查询后可以下载 xlsx。 查询可能需要几秒钟,所以我想在操作期间隐藏按钮。
我知道这通常是一个简单的操作,通过按钮上的js:
<asp:ImageButton id="Bt" OnClientClick=" this.style.display = 'none'; />
脚本结束时的服务器端:
Bt.Style.Add("display", "inline");
但为了制作 xslx,我使用以下代码:
response = System.Web.HttpContext.Current.Response;
response.ClearContent();
response.Clear();
response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
response.AddHeader("Content-Disposition", "attachment; filename=name.xlsx");
response.TransmitFile(file_path);
response.Flush();
response.End();
清除响应上下文不允许我在脚本中运行其他 javascript 代码(它只是不起作用),所以我不知道如何将按钮的可见性设置为内联。
【问题讨论】:
-
你是对的,它不会在服务器端工作,因为你向客户端提供了完全不同的响应——发送文件,而不是刷新页面。但同样,客户端无法检测下载何时完成(出于基本相同的原因 - 它是您实际页面上下文之外的完全独立的请求)。很多人都试图解决这个问题:google.co.uk/… 如您所见,没有可靠或简单的解决方案。
标签: javascript asp.net response httpresponse