从以下英文文档可得出解决方法:用Response.Redirect()或Response.Write()进行URL带参数的页面重定向时出现如题所示的错误。Ajax是无刷新的,而使用Response进行带参重定向时需要刷新页面。所以只须在UpdatePanel下设置“asp:PostBackTrigger”的“ControlID”为指定的控件名称即可,如:

1、页面上普通按钮

<Triggers>

<asp:PostBackTrigger ControlID="btnSave" />

</Triggers>

2、动态创建的按钮控件(如repeater或gridview里面):

使用ScriptManager.RegisterPostBackControl 方法

将控件注册为回发的触发器。 该方法用于配置 UpdatePanel 控件内以其他方式执行异步回发的回发控件。

RegisterPostBackControl 方法可将 UpdatePanel 控件内的回发控件注册为触发器。 使用这种方法注册的控件将更新整个页面,而不是只更新 UpdatePanel 控件的内容。 使用这种方法注册 UpdatePanel 控件外部的回发控件不会产生任何影响,因为默认情况下这些控件不执行异步回发。

Edf.UI.WebForm.UserControls.LinkButton linkDown = e.Row.FindControl("lbDown") as Edf.UI.WebForm.UserControls.LinkButton;if (null != linkDown){((ScriptManager)Master.FindControl("scm")).RegisterPostBackControl(linkDown);}

------------------------------------------------------------------------------------------------------------

参考的英文文档:

If you've used the Microsoft ASP.NET AJAX UpdatePanel control, there's a good chance you've hit the "Sys.WebForms.PageRequestManagerParserErrorException" error.

What's a PageRequestManagerParserErrorException?

The UpdatePanel control uses asynchronous postbacks to control which parts of the page get rendered. It does this using a whole bunch of JavaScript on the client and a whole bunch of C# on the server. Asynchronous postbacks are exactly the same as regular postbacks except for one important thing: the rendering. Asynchronous postbacks go through the same life cycles events as regular pages (this is a question I get asked often). Only at the render phase do things get different. We capture the rendering of only the UpdatePanels that we care about and send it down to the client using a special format. In addition, we send out some other pieces of information, such as the page title, hidden form values, the form action URL, and lists of scripts.

As I mentioned, this is rendered out using a special format that the JavaScript on the client can understand. If you mess with the format by rendering things outside of the render phase of the page, the format will be messed up. Perhaps the most common way to do this is to call Response.Write() during Page's Load event, which is something that page developers often do for debugging purposes.

The client ends up receiving a blob of data that it can't parse, so it gives up and shows you a PageRequestManagerParserErrorException. Here's an example of what the message contains:

---------------------------

Microsoft Internet Explorer

---------------------------

Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.

Details: Error parsing near 'Hello, World!106|upd'.

---------------------------

OK

---------------------------

If you ask me, this error message is not all that bad. After all, I'm the one that made it :) The details indicate what was being parsed when it decided to give up. You can see the part of the text from my Response.Write(), and immediately after that is part of the special format I keep mentioning.

Why do I keeping getting a PageRequestManagerParserErrorException?

Well, chances are you're doing one of the things mentioned in the error message. Here are the most common reasons and why they don't work:

Calls to Response.Write():

By calling Response.Write() directly you are bypassing the normal rendering mechanism of ASP.NET controls. The bits you write are going straight out to the client without further processing (well, mostly...). This means that UpdatePanel can't encode the data in its special format.

Response filters:

Similar to Response.Write(), response filters can change the rendering in such a way that the UpdatePanel won't know.

HttpModules:

Again, the same deal as Response.Write() and response filters.

Server trace is enabled:

If I were going to implement trace again, I'd do it differently. Trace is effectively written out using Response.Write(), and as such messes up the special format that we use for UpdatePanel.

Calls to Server.Transfer():

Unfortunately, there's no way to detect that Server.Transfer() was called. This means that UpdatePanel can't do anything intelligent when someone calls Server.Transfer(). The response sent back to the client is the HTML markup from the page to which you transferred. Since its HTML and not the special format, it can't be parsed, and you get the error.

How do I avoid getting a PageRequestManagerParserErrorException?

To start with, don't do anything from the preceding list! Here's a matching list of how to avoid a given error (when possible):

Calls to Response.Write():

Place an <asp:Label> or similar control on your page and set its Text property. The added benefit is that your pages will be valid HTML. When using Response.Write() you typically end up with pages that contain invalid markup.

Response filters:

The fix might just be to not use the filter. They're not used very often anyway. If possible, filter things at the control level and not at the response level.

HttpModules:

Same as response filters.

Server trace is enabled:

Use some other form of tracing, such as writing to a log file, the Windows event log, or a custom mechanism.

Calls to Server.Transfer():

I'm not really sure why people use Server.Transfer() at all. Perhaps it's a legacy thing from Classic ASP. I'd suggest using Response.Redirect() with query string parameters or cross-page posting.

Another way to avoid the parse error is to do a regular postback instead of an asynchronous postback. For example, if you have a button that absolutely must do a Server.Transfer(), make it do regular postbacks. There are a number of ways of doing this:

方法1:The easiest is to simply place the button outside of any UpdatePanels. Unfortunately the layout of your page might not allow for this.

方法2:Add a PostBackTrigger to your UpdatePanel that points at the button. This works great if the button is declared statically through markup on the page.

方法3:Call ScriptManager.RegisterPostBackControl() and pass in the button in question. This is the best solution for controls that are added dynamically, such as those inside a repeating template.

Summary

I hope I've answered a lot of questions here and not angered too many of you. We're looking at ways to improve some of these situations in the next version of ASP.NET, but of course there are no guarantees. If you avoid changing the response stream, you're good to go. If you absolutely must change the response stream, simply don't do asynchronous postbacks.

Sys.WebForms.PageRequestManagerParserErrorException 错误的解决办法相关推荐

  1. python自定义包或模块在Linux服务器导入错误的解决办法

    python自定义包或模块在Linux服务器导入错误的解决办法 在本地机器上跑python代码,自己定义的文件进行导包运行是没有问题,但是放到linux服务器上的时候就会提示 ImportError: ...

  2. python2发送http不编码_[转]Python 2.x中常见字符编码和解码方面的错误及其解决办法...

    Python 2.x中的字符编码,设计的的确不好,导致初学者,甚至是即使用Python很长时间的人,都会经常遇到字符编解码方面的错误. 下面就把一些常见情,尽量的都整理出来,并给出相应的解决办法. 看 ...

  3. Oracle常见ORA错误及解决办法

    Oracle常见ORA错误及解决办法 问题1 1.1 错误现象: EXP-00008: ORACLE error 1013 encountered ORA-01013: user requested ...

  4. Oracle的常见错误及解决办法

    ORA-12528: TNS:listener: all appropriate instances are blocking new connections ORA-12528问题是因为监听中的服务 ...

  5. php源码安装失败,php编译安装常见错误及解决办法

    php编译安装常见错误及解决办法 1.configure: error: No curses/termcap library found 网上有的说法是:–with-named-curses-libs ...

  6. sendmail服务器配置过程中出现的一些错误和解决办法

    sendmail服务器配置过程中出现的错误和解决办法 以前在做实验的过程中总结和写的一些教程的一些资料,一直没时间发布到博客上面,五一到了,终于有点时间发布啦!关于Linux上面还会有RHCE系列的学 ...

  7. Oracle10g安装中遇到的错误及解决办法

    linux解决xhost: unable to open display 实用技巧:在Linux下设置xhost方法步骤 第一步:用root登陆linux,启动vnc服务: 第二步:根据vnc起来的端 ...

  8. could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR 错误的解决办法

    could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR 错误的解决办法 增加如下代码: gpu_options = tf.GPUOptio ...

  9. hibernate开发错误及解决办法

    2019独角兽企业重金招聘Python工程师标准>>> hibernate开发错误及解决办法 <!-- attachment--> <!-- attachment ...

  10. 初学rpa的十大经典错误及解决办法_Python3之十大经典错误及其解决办法

    作者 | 严小样儿 来源 | 统计与数据分析实战 接触了很多Python爱好者,有初学者,亦有转行人.不论大家学习Python的目的是什么,总之,学习Python前期写出来的代码不报错就是极好的.下面 ...

最新文章

  1. DHTML中style的display和visibility属性
  2. sed替换ip地址为网关
  3. 构造方法和方法的重载。
  4. 学习React的一知半解
  5. Java进阶学习资料!dockerjar内存
  6. oracle转换请求无法实施,Oracle服务正常,但不响应请求的问题
  7. 【正则表达式】正则表达式匹配SQL中的函数名
  8. 我是小白0基础,现在我想学习前端开发,该如何系统的学习?
  9. 小米回应造车传闻;饿了么就春节“套路”骑手活动致歉;Go 1.16 正式发布 | 极客头条...
  10. ServiceStack 项目实例 010 ServiceStack.Northwind - 2
  11. 【优化求解】基于matalb改进的遗传算法求解IGA城市交通信号优化问题【含Matlab源码 215期】
  12. turbo c语言教程,C语言入门教程之 Turbo C程序的基本组成
  13. Esxi 6.7安装教程
  14. 如何快速设计《数字电路》的JK触发器、T触发器描述的驱动方程对应的次态K图——异或卡诺图法
  15. 【测绘程序设计】——大地坐标与空间直角坐标转换
  16. Windows Workflow Foundation中实现人工活动的demo,按照XPDL规范的实现
  17. 从浏览器中打开我们的应用
  18. 强化学习中的基础概念和术语——spinning up文档翻译
  19. 2020强网杯部分题目复现
  20. 微信小程序顶部透明状态标题栏搜索栏与胶囊对齐

热门文章

  1. 【风电功率预测】基于matlab遗传算法优化BP神经网络风电功率预测【含Matlab源码 760期】
  2. AMOS结构方程模型(SEM)简介【SPSS 049期】
  3. python中通过index删除list中的多个元素
  4. ROBOTSTXT_OBEY
  5. 第一章计算机基础知识作业答案,计算机基础作业题1答案
  6. php遍历path树,php 递归遍历文件树代码_PHP教程
  7. html word 打开,HTML以Word或Excel打开
  8. python defaultdict 递归_在Python中使用defaultdict初始化字典以及应用方法
  9. linux下tab作用的描述?
  10. 洗衣机的维修和电动机