我有一个调用此方法的asp.net按钮。
protected void DownloadFile(object sender, EventArgs e)
{
Response.Clear();
string filePath = getFilePath();
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition", "attachment; filename=FvGReport.xlsx");
Response.TransmitFile(filePath);
Response.End();
newReportMessage.Visible = false;
}
但是newReportMessage.Visible组件永远不能运行。通过阅读我可以看到Response.End()只是终止线程,所以这是有道理的。所以我尝试过对很多其他人有用的东西。
protected void DownloadFile(object sender, EventArgs e)
{
Response.Clear();
string filePath = getFilePath();
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition", "attachment; filename=FvGReport.xlsx");
Response.TransmitFile(filePath);
Response.Flush();
Response.SuppressContent = true;
HttpContext.Current.ApplicationInstance.CompleteRequest();
newReportMessage.Visible = false;
}
但它仍然不起作用?有谁知道问题是什么,所以我将来可以避免这种情况,解决方案是什么?