Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested UpdatePanel: Why does ChildrenAsTriggers have no effect?

Given a simple example with two nested Update-Panels. They are nested, and each one has a label which is filled with the current time in the code behind. I don't understand why the ChildrenAsTriggers="true" - Property on the outer UpdatePanel has no effect? When I hit the 'Update Nested Panel' - button, the time in the parent UpdatePanel is not updated. But as far as I understand the property, it should be:

<asp:ScriptManager ID="ScriptManager1" runat="server" 
    onasyncpostbackerror="ScriptManager1_AsyncPostBackError">
</asp:ScriptManager>

<asp:Button ID="ButtonUpdate" runat="server" Text="Update Panel 1"
    style="margin-top: 15px" onclick="ButtonUpdate_Click" />
<asp:Button ID="ButtonUpdateNestedPanel" runat="server" Text="Update Nested Panel"
    style="margin-top: 15px" onclick="ButtonUpdateNestedPanel_Click" />

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="ButtonUpdate" EventName="Click" />
    </Triggers>
    <ContentTemplate>
        <asp:Label ID="Label1" runat="server" />

        <asp:UpdatePanel ID="UpdatePanelNested" runat="server">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="ButtonUpdateNestedPanel" EventName="Click" />
            </Triggers>
            <ContentTemplate>
                <asp:Label ID="LabelNested" runat="server" />
            </ContentTemplate>
        </asp:UpdatePanel>

    </ContentTemplate>
</asp:UpdatePanel>

Thx for any tipps! sl3dg3

p.s.: code behind:

protected void ButtonUpdate_Click(object sender, EventArgs e)
{
    LabelNested.Text = DateTime.Now.ToString();
    Label1.Text = DateTime.Now.ToString();
}
protected void ButtonUpdateNestedPanel_Click(object sender, EventArgs e)
{
    LabelNested.Text = DateTime.Now.ToString();
    Label1.Text = DateTime.Now.ToString();
}
like image 353
sl3dg3 Avatar asked Nov 25 '22 13:11

sl3dg3


1 Answers

When the ChildrenAsTriggers property is set to true and any child control of the UpdatePanel control causes a postback. Child controls of nested UpdatePanel controls do not cause an update to the outer UpdatePanel control unless they are explicitly defined as triggers for the parent panel. http://forums.asp.net/t/1422425.aspx/1

and this should be like...

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="ButtonUpdate" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="ButtonUpdateNestedPanel" EventName="Click" />
        </Triggers>
......   
......
like image 179
Muhammad Akhtar Avatar answered Apr 26 '23 21:04

Muhammad Akhtar