首页 > 其他 > 详细

(转)Response.Write()方法的服务器控件在使用UpdatePanel的的解决法

时间:2014-01-18 01:37:28      阅读:419      评论:0      收藏:0      [点我收藏+]

.如果调用Response.Write()方法的服务器控件在使用UpdatePanel的页面,则只需要在UpdatePanel下增加一个<Triggers>节点,通过PostBackTrigger注册一下改控件就可以了。代码如下:

   1. <asp:ScriptManager ID="ScriptManager1" runat="server">
   2.         </asp:ScriptManager>
   3.         <asp:UpdatePanel ID="UpdatePanel1" runat="server">
   4.             <Triggers>
   5.                     <asp:PostBackTrigger ControlID="Button2" />    <!--Button2就是下面那个需要在Button2_Click事件里使用Response.Write()的按钮ID-->
   6.             </Triggers>
   7.             <ContentTemplate>           
   8.                 <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Button" />
   9.                 <asp:UpdateProgress ID="UpdateProgress1" runat="server">
  10.                 <ProgressTemplate></ProgressTemplate>
  11.                 </asp:UpdateProgress>
  12.             </ContentTemplate>
  13.         </asp:UpdatePanel>

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
这样,问题就解决了。

本文转自:http://www.ximenyifan.com/article/157.html

(转)Response.Write()方法的服务器控件在使用UpdatePanel的的解决法

原文:http://www.cnblogs.com/BBLY/p/3524665.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!