错误:The message received from the server could not be parsed.
2013-04-27 10:51
507 查看
在使用UpdatePanel的时候,如果要用到Response.Write()方法,则会出错,错误信息内容大概如下:
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 ' 你要输出的内容|UpdatePanel|U'
解决方法如下:
1.如果调用Response.Write()方法的服务器控件在使用UpdatePanel的页面,则只需要在UpdatePanel下增加一个<Triggers>节点,
通过PostBackTrigger注册一下改控件就可以了。代码如下:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="Button1" /> <!--Button2就是下面那个需要在Button1_Click
事件里使用Response.Write()的按钮ID-->
</Triggers>
<ContentTemplate>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate></ProgressTemplate>
</asp:UpdateProgress>
</ContentTemplate>
</asp:UpdatePanel>
2.但是,如果是在母版页中使用UpdatePanel,则不能通过以上方法来解决,否则或出现类似以下错误:
A control with ID 'btnLogin' could not be found for the trigger in UpdatePanel 'UpdatePanel1'.
这主要是UpdatePanel1找不到<asp:PostBackTrigger ControlID="btnLogin" />中注册的控件,因为,我们一般没有在母版页中
添加这个控件(btnLogin)。(当然,如果在UpdatePanel的<ContentTemplate> 节点下添加了ID为btnLogin的控件,则不会出
错。)
如果出现这样的错误该怎么办呢,我的解决方法是在需要用到Response.Write()方法的控件所在页码的Page_Load事件中添加如下
代码:
((ScriptManager)Master.FindControl("ScriptManager1")).RegisterPostBackControl(btnLogin);
//ScriptManager1是<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>的ID
这样,问题就解决了。
下面是我的一个项目中的代码:
母版页前台代码:
<asp:ScriptManager runat="server" ID="ScriptManager1">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
<table class="progressBox" style="width: 200px">
<tr>
<td>
<asp:Image runat="server" ID="imgLoad"
ImageUrl="~/App_Themes/SkinFile/Images/animated_loading.gif" />
</td>
<td>
正在从服务器下载数据...
</td>
</tr>
</table>
</ProgressTemplate>
</asp:UpdateProgress>
</ContentTemplate>
<asp:UpdatePanel>
子页面后台代码:
protected void Page_Load(object sender, EventArgs e)
{
((ScriptManager)Master.FindControl("ScriptManager1")).RegisterPostBackControl(btnLogin);
}
这样,当按钮btnLogin的单击事件中用到:Response.Write()方法时,就不会出现题目中的错误了。
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 ' 你要输出的内容|UpdatePanel|U'
解决方法如下:
1.如果调用Response.Write()方法的服务器控件在使用UpdatePanel的页面,则只需要在UpdatePanel下增加一个<Triggers>节点,
通过PostBackTrigger注册一下改控件就可以了。代码如下:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="Button1" /> <!--Button2就是下面那个需要在Button1_Click
事件里使用Response.Write()的按钮ID-->
</Triggers>
<ContentTemplate>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate></ProgressTemplate>
</asp:UpdateProgress>
</ContentTemplate>
</asp:UpdatePanel>
2.但是,如果是在母版页中使用UpdatePanel,则不能通过以上方法来解决,否则或出现类似以下错误:
A control with ID 'btnLogin' could not be found for the trigger in UpdatePanel 'UpdatePanel1'.
这主要是UpdatePanel1找不到<asp:PostBackTrigger ControlID="btnLogin" />中注册的控件,因为,我们一般没有在母版页中
添加这个控件(btnLogin)。(当然,如果在UpdatePanel的<ContentTemplate> 节点下添加了ID为btnLogin的控件,则不会出
错。)
如果出现这样的错误该怎么办呢,我的解决方法是在需要用到Response.Write()方法的控件所在页码的Page_Load事件中添加如下
代码:
((ScriptManager)Master.FindControl("ScriptManager1")).RegisterPostBackControl(btnLogin);
//ScriptManager1是<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>的ID
这样,问题就解决了。
下面是我的一个项目中的代码:
母版页前台代码:
<asp:ScriptManager runat="server" ID="ScriptManager1">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
<table class="progressBox" style="width: 200px">
<tr>
<td>
<asp:Image runat="server" ID="imgLoad"
ImageUrl="~/App_Themes/SkinFile/Images/animated_loading.gif" />
</td>
<td>
正在从服务器下载数据...
</td>
</tr>
</table>
</ProgressTemplate>
</asp:UpdateProgress>
</ContentTemplate>
<asp:UpdatePanel>
子页面后台代码:
protected void Page_Load(object sender, EventArgs e)
{
((ScriptManager)Master.FindControl("ScriptManager1")).RegisterPostBackControl(btnLogin);
}
这样,当按钮btnLogin的单击事件中用到:Response.Write()方法时,就不会出现题目中的错误了。
相关文章推荐
- The message received from the server could not be parsed 错误解决方法
- The message received from the server could not be parsed 错误解决方法
- 解决问题: The message received from the server could not be parsed
- The message received from the server could not be parsed
- WCF分布式开发常见错误(23):This could be due to the fact that the server certificate is not configured properly with HTTP.SYS
- jdbc启动错误(The driver has not received any packets from the server)
- jdbc启动错误(The driver has not received any packets from the server)
- 错误中学习--Connections could not be acqu 4000 ired from the underlying database
- Claims系列 - ID4036错误(The key needed to decrypt the encrypted security token could not be resolved from the following security key identifier)
- JDBC出现这个错误的解决办法Connections could not be acquired from the underlying database!
- 安装完成postgresql 后,启动大象pgAdmin4 报the application server could not be contect 错误
- install LuaForWindow 提示The server name or address could not be resolved. 错误
- msxml3.dll 错误 '80072efd' A connection with the server could not be established
- from scipy import spatial 出现 from .qhull import * ImportError: DLL load failed: The specified module could not be found. 错误
- jdbc启动错误(The driver has not received any packets from the server)
- 解决c3p0:Connections could not be acquired from the underlying database!
- 关于创建FLex项目时候的 Cannot access the web server. The server may not be running, or the web root folder or root URL may be invalid.错误
- 错误代码: Could not load the "XXX.png" image referenced from a nib in the bundle with identifier "XXX"
- xcode 7.0 错误提示 The resource could not be loaded because the App Transport Security policy requires
- iOS 上架app的过程当中出现the Info.plist is missing or could not be parsed.经历