使用PageRequestManagerParserErrorException从UpdatePanel动态生成下载失败

时间:2010-02-05 19:01:21

标签: asp.net download updatepanel

我是ASP.NET AJAX的新手,遇到了问题。

该页面使用UpdatePanel和Timer来检查批处理队列的新结果。当结果可用时,它应显示下载结果文件的链接。

我正在使用转发器格式化使用LinkBut​​tons的链接:

<asp:LinkButton ID="linkOutputFile" runat="server" OnCommand="linkOutputFile_Command" CommandArgument='<%# Container.DataItem %>'><%# Container.DataItem %></asp:LinkButton>

数据项位于wwwroot之外的文件夹中,所以我让这个命令处理程序自动生成下载:

protected void linkOutputFile_Command (object sender, CommandEventArgs e)
{
 String strFile = e.CommandArgument as String;
 String strExt = Path.GetExtension(strFile).ToLower();
 String strSourceFile = Path.Combine(Common.UploadFolder, strFile);

 Response.ContentType = "text/plain"; // all results files are text
 Response.AddHeader("content-disposition", "attachment; filename=" + strFile);
 Response.Buffer = true;
 Response.Write(File.ReadAllText(strSourceFile));
 Response.End();
}

显示和更新的所有内容都可以正常工作,但是当点击链接时,我得到一个PageRequestManagerParserErrorException,详细信息显示“在'xxx'附近解析错误”,其中'xxx'是文件中的内容。

我相信文件正在被正确读取,并且通常这可以工作,除了UpdatePanel我对Response.Write的调用有问题。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

尝试重定向到将发送文件的处理程序。 比如“download.ashx?file =”+ e.CommandArgument

相关问题