updatepanel中使用alert弹出框方法(两种)
来源:互联网 发布:mysql 连接远程数据库 编辑:程序博客网 时间:2024/04/30 02:24
在使用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'
解决方法如下:
2.但是,如果是在母版页中使用UpdatePanel,则不能通过以上方法来解决,否则或出现类似以下错误:
A control with ID 'btnExport' could not be found for the trigger in UpdatePanel 'UpdatePanel1'.
这主要是UpdatePanel1找不到<asp:PostBackTrigger ControlID="btnExport" />中注册的控件,因为,我们一般没有在母版页中添加这个控件(btnExport)。(当然,如果在UpdatePanel的<ContentTemplate> 节点下添加了ID为btnExport的控件,则不会出错。)
如果出现这样的错误该怎么办呢,我的解决方法是在需要用到Response.Write()方法的控件所在页码的Page_Load事件中添加如下代码:
((ScriptManager)Master.FindControl("ScriptManager1")).RegisterPostBackControl(btnExport);
//ScriptManager1是<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>的ID
这样,问题就解决了。
下面是我的一个项目中的代码:
母版页前台代码:
子页面后台代码:
这样,当按钮btnExport的单击事件中用到: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="Button2" /> <!--Button2就是下面那个需要在Button2_Click事件里使用Response.Write()的按钮ID-->
- </Triggers>
- <ContentTemplate>
- <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Button" />
- <asp:UpdateProgress ID="UpdateProgress1" runat="server">
- <ProgressTemplate></ProgressTemplate>
- </asp:UpdateProgress>
- </ContentTemplate>
- </asp:UpdatePanel>
A control with ID 'btnExport' could not be found for the trigger in UpdatePanel 'UpdatePanel1'.
这主要是UpdatePanel1找不到<asp:PostBackTrigger ControlID="btnExport" />中注册的控件,因为,我们一般没有在母版页中添加这个控件(btnExport)。(当然,如果在UpdatePanel的<ContentTemplate> 节点下添加了ID为btnExport的控件,则不会出错。)
如果出现这样的错误该怎么办呢,我的解决方法是在需要用到Response.Write()方法的控件所在页码的Page_Load事件中添加如下代码:
((ScriptManager)Master.FindControl("ScriptManager1")).RegisterPostBackControl(btnExport);
//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(btnExport);
- }
这样,当按钮btnExport的单击事件中用到:Response.Write()方法时,就不会出现题目中的错误了。
0 0
- updatepanel中使用alert弹出框方法(两种)
- updatepanel中使用alert弹出框方法(两种)
- updatepanel中使用alert弹出框方法(两种)
- asp.net 下面 updatepanel中使用alert弹出框方法(两种)
- [转]updatepanel中使用alert弹出框方法
- updatepanel 中使用JS alert方法
- updatepanel中使用alert
- ajax 在updatepanel中使用alert提示方法
- ajax 在updatepanel中使用alert提示方法
- asp.net ajax 在updatepanel中使用alert提示方法
- AJAX使用了UpdatePanel后无法使用alert弹出脚本
- AJAX使用了UpdatePanel后无法使用alert弹出脚本
- 两种弹出MessageBox的方法,类似MTK中的alert
- updatepanel里面使用使用弹出消息框的方法
- updatepanel中alert的问题
- UpdatePanel 弹出提示的几种方法
- UpdatePanel中让JS输出Alert
- 使用UpdatePanel,在后台调用alert
- 苹果的icloud目前有部分的服务是托管在亚马逊AWS和微软的AZURE上
- Oracle SQL优化
- MySQL记录存在则更新,不存在则插入
- iOS中label根据字体和行间距返回高度
- Spring MVC使用Cron表达式的定时器
- updatepanel中使用alert弹出框方法(两种)
- 一道有趣的编程题
- ANSYS 17.0下载 64位 附安装教程
- 记又一次面试失败的经历
- APC注入
- Android自定义View——可在背景图和前景图显示遮罩效果的ImageView
- mysql主从复制(超简单)
- Android开发者网址导航
- union+join