Gridview ItemTemplate中的updatePanel在回发时出现问题

时间:2014-02-06 05:27:54

标签: 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

我该如何解决?

2 个答案:

答案 0 :(得分:1)

UpdatePanel_Unload添加到OnUnload的{​​{1}}事件中:

UpdatePanel

在代码中添加

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

Adding/removing UpdatePanels dynamicaly from a page

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

答案 1 :(得分:1)

根据Ali Dehghan Tarzeh的回答:

  

您应该将UpdatePanel_Unload添加到的OnUnload事件中   UpdatePanel中:

<asp:UpdatePanel ID="UpdatePanel1" 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 });
}