Pergunta

In my gridItemTemplate , I have Update panel and check box ,

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

First time running has no error , but after postback , I got this error

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

How can I solve it ?

Foi útil?

Solução

Add the UpdatePanel_Unload to the OnUnload event of the UpdatePanel:

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

Add this in code behind

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

Outras dicas

According to Ali Dehghan Tarzeh' answer:

you should add the UpdatePanel_Unload to the OnUnload event of the UpdatePanel:

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

In Code behind :

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 });
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top