c# - Gridview ItemTemplate 中的 updatePanel 在回发时存在问题

标签 c# asp.net checkbox updatepanel postback

在我的 gridItemTemplate 中,我有更新面板和复选框,

<ItemTemplate>
   <asp:UpdatePanel runat="server" ID="upChkOption">
       <ContentTemplate>   
           <asp:CheckBox runat="server" ID="chkOption" AutoPostBack="true"   
            OnCheckedChanged="chkOption_CheckChanged">                                
       </ContentTemplate>
    </asp:UpdatePanel>
</ItemTemplate>

第一次运行没有错误,但是在postback之后,我得到了这个错误

Cannot unregister UpdatePanel with ID 'upChkOption' since it was not registered with   
the ScriptManager. This might occur if the UpdatePanel was removed from the control  
tree and later added again, which is not supported. Parameter name: updatePanel

如何解决?

最佳答案

UpdatePanel_Unload添加到UpdatePanelOnUnload事件中:

<asp:UpdatePanel ID="upChkOption" runat="server" OnUnload="UpdatePanel_Unload">

将其添加到代码后面

protected void UpdatePanel_Unload(object sender, EventArgs e) 
      {
 MethodInfo methodInfo = typeof(ScriptManager).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)
            .Where(i => i.Name.Equals("System.Web.UI.IScriptManagerInternal.RegisterUpdatePanel")).First();
  methodInfo.Invoke(ScriptManager.GetCurrent(Page),
            new object[] { sender as UpdatePanel });
    }

Adding/removing UpdatePanels dynamicaly from a page

cannot-unregister-updatepanel-since-it-was-not-registered-with-the-scriptmanager-error

关于c# - Gridview ItemTemplate 中的 updatePanel 在回发时存在问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21594761/

相关文章:

c# - 在桌面应用程序中管理 session 的 Ninject 范围

c# - 根据当前 IPrincipal 查找用户邮箱

html - 在打印期间更改字体

c++ - Qt复选框选中所有按钮

c# - JSON.Net 反序列化错误将值设置为属性

c# - C# 的访问修饰符在 Java 和 Scala 中的等价物是什么?

将方法组作为委托(delegate)传递时,C# 调用不明确

c# - 如何在对象的 IList 中找到重复的属性值并合并它们?

vb.net动态创建复选框

java - 如何在动态生成 Id 值时检索复选框的值