【发布时间】:2015-03-10 09:35:19
【问题描述】:
我有一个 C# 程序,用于下载生成的 Word 文档。此外,在生成它之后,UI 中的“沙漏”属性必须重置为默认值。为此,我使用 scriptmanager 调用一个 javascript 函数,该函数只有在语句出现在最后时才能执行。不幸的是,前一步有一个下载word文档的代码。当它发生时,程序会丢失并且永远不会返回并执行脚本管理器所在的程序的剩余部分以停止沙漏。将脚本管理器放在下载代码之前也无济于事。我深受这个特殊问题的困扰。请帮忙,谢谢!!
下面是代码,
private void DownloadFile(string filename)
{
System.IO.FileInfo file = new System.IO.FileInfo(filename);
if (file.Exists)
{
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.FullName);
HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
HttpContext.Current.Response.ContentType = "Application/msword";
HttpContext.Current.Response.WriteFile(file.FullName);
//HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "script", "stopHourglass()", true);
}
}
【问题讨论】:
-
您是否在相关代码块中将
try到catch可能是exception?异常可能会被抑制,具体取决于调用上下文...
标签: c# asp.net scriptmanager