ASP.Net中的错误:Sys.WebForms.PageRequestManagerParserErrorException [英] Error in ASP.Net: Sys.WebForms.PageRequestManagerParserErrorException

查看:57
本文介绍了ASP.Net中的错误:Sys.WebForms.PageRequestManagerParserErrorException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了2个页面的imageBtn_Click(对象发送者,ImageClickEventArgs e)来打开PDF文件。它适用于1页但不适用于另一页,即使我使用相同的代码。

I created the imageBtn_Click(object sender, ImageClickEventArgs e) for 2 pages to open a PDF file. It works well for 1 page but not for another one even though I used the identical code.

void imageBtn_Click(object sender, ImageClickEventArgs e) {
    string pdfPath = g.sFolder + "GIS Strategic Plan Final 080314.pdf";
    WebClient client = new WebClient();
    Byte[] buffer = client.DownloadData(pdfPath);
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-length", buffer.Length.ToString());
    Response.BinaryWrite(buffer);
}



我得到的错误是:

Sys.WebForms.PageRequestManagerParserErrorException:无法解析从服务器收到的消息。我想知道为什么这段代码在其中一个页面上失败了。如果可以的话请帮忙。谢谢。


The error I got is:
Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. I wonder why this piece of code got failure for one of the page. Please help if you can. Thanks.

推荐答案

似乎问题在于您的文件名。你的文件名有空格,这是我的问题。尝试通过双引号重叠您的文件路径,如下所示。

It seems like problem is with your file name. Your file name has spaces which my be an issue. Try by eclosing your file path by double quotes as below.
string pdfPath = "\"" +  g.sFolder + "GIS Strategic Plan Final 080314.pdf\"";


RaisKazi:感谢您的帖子。检查但事实并非如此。正如我在我的帖子中所提到的,我从另一个aspx中移植了完全相同的代码。文件(在同一个项目中)。另一个工作正常。 Somethin对我来说很陌生。

我在两个aspx中重新检查了我的代码(1个工作正常但另外1个没有)。一个运作良好的代码如下:

RaisKazi: Thanks for your post. Checked but it is not the case. As mentioned in my inital post, I transplaned the exact the same code from another aspx. file (in the same project). Another one works fine. Somethin is stranger to me.
I re-checked my code in both aspx (1 works well but another 1 not). The code for the one working well is below:
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/PDF.jpg"
    onclick="ImageButton1_Click" style="height: 16px"/>





和后面的代码:



and the code behind:

protected void ImageButton1_Click(object sender, ImageClickEventArgs e) {
    WebClient client = new WebClient();
    Byte[] buffer = client.DownloadData(path);
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-length", buffer.Length.ToString());
    Response.BinaryWrite(buffer);
}





一个不起作用如下:



The one does not working likes that below:

<div>
    <asp:ScriptManager ID="ScriptManager1" runat="server"/>

    <asp:updatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:PlaceHolder runat="server" ID="placeholder1"/>
        </ContentTemplate>
    </asp:updatePanel>
</div>





后面的代码在方法中运行相同的代码:



The code behind runs the same code in the method:

public void imageBtn_Click(object sender, ImageClickEventArgs e)   {
    ......
    string pdfPath = g.sFolder + myPdf;
    WebClient client = new WebClient();
    Byte[] buffer = client.DownloadData(pdfPath);
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-length", buffer.Length.ToString());
    Response.BinaryWrite(buffer);
}



如何解决这个问题?谢谢,如果你能提供你的提示。


How can this problem be solved? Thanks if you can provide your hint.


通过参考 [ ^ ]。我添加了

ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);

...

scriptManager.RegisterPostBackControl(imageBtn);

The problem has been solved by referring the post at .[^]. I added
ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
...
scriptManager.RegisterPostBackControl(imageBtn);
in the Page_Load().


这篇关于ASP.Net中的错误:Sys.WebForms.PageRequestManagerParserErrorException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆