【问题标题】:updatePanel in Griview ItemTemplate has issue on postbackGridview ItemTemplate 中的 updatePanel 在回发时出现问题
【发布时间】:2014-03-02 22:01:29
【问题描述】:

在我的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

我该如何解决?

【问题讨论】:

标签: c# asp.net checkbox updatepanel postback


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    根据 Ali Dehghan Tarzeh 的回答:

    您应该将 UpdatePanel_Unload 添加到 更新面板:

    <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 });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-28
      相关资源
      最近更新 更多