开发者

Dynamically generating download from UpdatePanel fails with PageRequestManagerParserErrorException

开发者 https://www.devze.com 2022-12-19 13:43 出处:网络
I am new to ASP.NET AJAX and am encountering a problem. The page uses an UpdatePanel and Timer to check for new results of a batch processing queue.When results are available, it should show links to

I am new to ASP.NET AJAX and am encountering a problem.

The page uses an UpdatePanel and Timer to check for new results of a batch processing queue. When results are available, it should show links to download results files.

I'm using a repeater to format the links, which use LinkButtons:

<asp:LinkButton ID="linkOutputFile" runat="server" OnCommand="li开发者_如何学编程nkOutputFile_Command" CommandArgument='<%# Container.DataItem %>'><%# Container.DataItem %></asp:LinkButton>

The data items are in a folder outside of wwwroot, so I have this command handler automatically generate the download:

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();
}

Everything with display and updating works fine, but when the links are clicked, I get a PageRequestManagerParserErrorException and the details show "Error parsing near 'xxx'", where the 'xxx' is content from the files.

I believe the files are being read correctly, and normally this would work except the UpdatePanel is having trouble with my calls to Response.Write. How can I fix this?


Try redirecting to a handler that will send the file. like "download.ashx?file=" + e.CommandArgument

0

精彩评论

暂无评论...
验证码 换一张
取 消