Search code examples
asp.netupdatepanel

Update Pannel Trigger not working


I have this html that contains a UpdatePanel and a Button, I would like update my User Control(that have a UpdatePanel too) when Button click I get this error: A control with ID 'btnSubmit' could not be found for the trigger in UpdatePanel when page load.

<asp:Content ID="Content1" ContentPlaceHolderID="content" runat="server">

        <asp:UpdatePanel runat="server" ID="updatePanelMyUC" UpdateMode="Conditional" ChildrenAsTriggers="false">

            <ContentTemplate>
                <uc1:myUserControl runat="server" ID="myUserControlID"/>
            </ContentTemplate>

            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btnSubmit" EventName="Click" />
            </Triggers>
        </asp:UpdatePanel>


    </asp:Content>

    <asp:Content ID="Content2" ContentPlaceHolderID="rightcolumn" runat="server">
        <asp:ImageButton ID="btnSubmit" ImageUrl="../../Resources/btnSubmit.png" runat="server" OnClick="btnSubmit_Click" />
    </asp:Content>

Solution

  • Your btnSubmit is outside the UpdatePanel. Trigger of the UpdatePanel must be inside the ContentTemplate of the said UpdatePanel.

    <asp:Content ID="Content1" ContentPlaceHolderID="content" runat="server">
    
        <asp:UpdatePanel runat="server" ID="updatePanelMyUC" UpdateMode="Conditional" ChildrenAsTriggers="false">
    
            <ContentTemplate>
                <uc1:myUserControl runat="server" ID="myUserControlID"/>
                <asp:ImageButton ID="btnSubmit" ImageUrl="../../Resources/btnSubmit.png" runat="server" OnClick="btnSubmit_Click" />
            </ContentTemplate>
    
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btnSubmit" EventName="Click" />
            </Triggers>
        </asp:UpdatePanel>
    
    
    </asp:Content>
    
    <asp:Content ID="Content2" ContentPlaceHolderID="rightcolumn" runat="server">
    </asp:Content>