嵌套的UpdatePanel:为什么ChildrenAsTriggers没有效果?

问题描述

| 给定一个简单的示例,其中包含两个嵌套的Update-Panels。它们是嵌套的,每个都有一个标签,该标签在后面的代码中充满了当前时间。我不明白为什么外部UpdatePanel上的
ChildrenAsTriggers=\"true\"
属性无效?当我点击\'Update Nested Panel \'-按钮时,父UpdatePanel中的时间不会更新。但据我了解,该物业应为:
<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>
谢谢你的小费! sl3dg3 附:后面的代码:
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();
}
    

解决方法

  当ChildrenAsTriggers属性设置为true时,UpdatePanel控件的任何子控件都会导致回发。嵌套的UpdatePanel控件的子控件不会导致外部UpdatePanel控件的更新,除非将它们明确定义为父面板的触发器。   http://forums.asp.net/t/1422425.aspx/1 这应该像...
<asp:UpdatePanel ID=\"UpdatePanel1\" runat=\"server\" UpdateMode=\"Conditional\" ChildrenAsTriggers=\"true\">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID=\"ButtonUpdate\" EventName=\"Click\" />
            <asp:AsyncPostBackTrigger ControlID=\"ButtonUpdateNestedPanel\" EventName=\"Click\" />
        </Triggers>
......   
......
    ,我相信,为了看到预期的效果,您实际上应该将按钮作为子级添加到内容模板中。 \“ ChildrenAsTriggers \”属性仅适用于\“ ContentTemplate \”块的直接子级。     ,ChildrenAsTriggers = \“真” 如果希望从UpdatePanel控件的直接子控件进行回发以导致面板内容的更新,则将ChildrenAsTriggers属性设置为true。除非您显式调用Update方法或将子控件定义为触发器,否则嵌套UpdatePanel控件的子控件将不会导致父UpdatePanel控件内容的更新。     

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...