2014-02-06 2 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-causes-the-cannot-unregister-updatepanel-error –

ответ

1

Добавьте UpdatePanel_Unload к OnUnload событие 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

По словам Али Deh Ghan 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 }); 
} 
Смежные вопросы