Search code examples
asp.netupdatepanel

Cannot find Nested UpdatePanel created from async postback


I have an UpdatePanel in which it contains a ListView. In the ListView, it contains another UpdatePanel. I wanted to add a new row inside the listview, meaning that the new row will have an UpdatePanel. But I'm getting the following error:

0x800a139e - JavaScript runtime error: Sys.InvalidOperationException: Could not 
find UpdatePanel with ID 'PageContent_lvwUser_updtPnlUserRole_1'. If it is 
being updated dynamically then it must be inside another UpdatePanel.

My code:

<asp:UpdatePanel ID="updtPnlUser" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
    <ContentTemplate>            
        <asp:ListView ID="lvwUser" runat="server" 
             InsertItemPosition="FirstItem" 
             OnItemDataBound="lvwUser_ItemDataBound" 
             OnItemInserting="lvwUser_ItemInserting" 
             OnItemDeleting="lvwUser_ItemDeleting"                           
             OnPagePropertiesChanging="lvwUser_PagePropertiesChanging" 
             OnPagePropertiesChanged="lvwUser_PagePropertiesChanged">
             <LayoutTemplate>
             ...
             </LayoutTemplate>
             <ItemTemplate>
             ...
                 <asp:UpdatePanel ID="updtPnlUserRole" runat="server">
                     <ContentTemplate>     
                         <asp:ListView ID="lvwUserRole" runat="server" 
                             InsertItemPosition="FirstItem" 
                             OnItemDataBound="lvwUserRole_ItemDataBound" 
                             OnItemInserting="lvwUserRole_ItemInserting" 
                             OnItemDeleting="lvwUserRole_ItemDeleting">
                             <LayoutTemplate>
                             ...
                             </LayoutTemplate>
                         </asp:ListView>
                     </ContentTemplate>
                </asp:UpdatePanel>
             </ItemTemplate>
             ...
         </asp:ListView>
     </ContentTemplate>
 </asp:UpdatePanel>

Since the InsertItem is in the first position, index 0 will contain the new row. So index 1 is the data before I add the new row.

Any ideas?


Solution

  • Solved by using ChildrenAsTriggers="true" in the parent UpdatePanel.

    <asp:UpdatePanel ID="updtPnlUser" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">