2014-02-06 66 views
2

問題在我gridItemTemplate,我有更新面板複選框,的UpdatePanel在Griview ItemTemplate中對回傳

<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 

我該如何解決?

+1

的http:// stackoverflow.com/questions/238915/what-c​​auses-the-cannot-unregister-updatepanel-error –

回答

1

添加UpdatePanel_UnloadOnUnload事件UpdatePanel的:

<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

1

據阿里·德赫的Ghan Tarzeh」回答:

你應該UpdatePanel_Unload添加到 的UpdatePanel的onunload事件:

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