ASP.Net 多个更新面板在不应该更新时进行更新

发布于 11-30 05:42 字数 4163 浏览 0 评论 0原文

我在网页上有一些更新面板全部设置为 UpdateMode="Conditional",但是当触发其中一个更新面板上的 AsyncPostBackTrigger 时,所有更新面板都会刷新。

以下是更新面板 HTML 标记之一:

<asp:UpdatePanel ID="pnls1FieldUpdate" runat="server" 
                 UpdateMode="Conditional">
    <ContentTemplate>
        <table class="FillInGrid" cellpadding="0" cellspacing="0">
            <tr>
                <td>
                    <asp:TextBox ID="txtS1ExpDate" runat="server" Width="67px" TabIndex="14"></asp:TextBox>
                    <asp:ImageButton ID="cmdS1ExpDate" runat="server" 
                         ImageUrl="~/images/calendar.png" TabIndex="15" />
                    <asp:CalendarExtender ID="CalendarExtender6" runat="server" TargetControlID="txtS1ExpDate" PopupButtonID="cmdS1ExpDate" Format="dd/MM/yyyy">
                    </asp:CalendarExtender>
                </td>
                <td>
                    <asp:DropDownList ID="cboS1ExpenseItem" runat="server" Width="200px" 
                        onselectedindexchanged="cboS1ExpenseItem_SelectedIndexChanged" 
                        AutoPostBack="True" TabIndex="16">
                    </asp:DropDownList>
                </td>
                <td>
                    <asp:TextBox ID="txtS1ExpAmt" runat="server" Width="78px" ontextchanged="txtS1ExpAmt_TextChanged" TabIndex="18" AutoPostBack="True"></asp:TextBox>
                </td>
                <td>
                    <asp:TextBox ID="txtS1ExpGST" runat="server" Width="78px" TabIndex="19"></asp:TextBox>
                </td>
                <td>
                <asp:TextBox ID="txtS1ExpOC" runat="server" Width="78px" 
                        ontextchanged="txtS1ExpOC_TextChanged" TabIndex="20" AutoPostBack="True"></asp:TextBox>
                </td>
                <td>
                    <asp:Button ID="cmdAddSection1Exp" runat="server" Text="Add" Width="80px" 
                        onclick="cmdAddSection1Exp_Click" TabIndex="21" /></td>
            </tr>
            <tr>
                <td colspan="6">
                    <table>
                        <tr>
                            <td class="HdrGnrl tRt" style="width:105px;">Sub item</td>
                            <td style="width:220px;">
                                <asp:DropDownList ID="cboS1ExpenseSubItem" runat="server" Width="200px" 
                                    TabIndex="17">
                                </asp:DropDownList>
                            </td>
                            <td style="width:85px;"></td>
                            <td style="width:85px;"></td>
                            <td style="width:85px;"></td>
                            <td style="width:100px;"></td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="txtS1ExpAmt" EventName="TextChanged" />
        <asp:AsyncPostBackTrigger ControlID="txtS1ExpOC" EventName="TextChanged" />
        <asp:AsyncPostBackTrigger ControlID="cboS1ExpenseItem" EventName="SelectedIndexChanged" />
    </Triggers>
</asp:UpdatePanel>
<asp:UpdatePanelAnimationExtender ID="UpdatePanelAnimationExtender4" TargetControlID="pnls1FieldUpdate" runat="server">
    <Animations>
        <OnUpdating>
            <Sequence>
                <FadeOut AnimationTarget="pnlExpense" minimumOpacity=".2" />
            </Sequence>
        </OnUpdating>
        <OnUpdated>
            <Sequence>
                <FadeIn AnimationTarget="pnlExpense" minimumOpacity=".2" />
            </Sequence>
        </OnUpdated>
    </Animations>
</asp:UpdatePanelAnimationExtender>

为什么所有不应该更新的更新面板都更新了?

I have some Update Panels on a webpage all set to UpdateMode="Conditional", however when the AsyncPostBackTrigger on one of the Update Panels is triggered, all of the Update Panels refresh.

The following is one of the update panel HTML markup:

<asp:UpdatePanel ID="pnls1FieldUpdate" runat="server" 
                 UpdateMode="Conditional">
    <ContentTemplate>
        <table class="FillInGrid" cellpadding="0" cellspacing="0">
            <tr>
                <td>
                    <asp:TextBox ID="txtS1ExpDate" runat="server" Width="67px" TabIndex="14"></asp:TextBox>
                    <asp:ImageButton ID="cmdS1ExpDate" runat="server" 
                         ImageUrl="~/images/calendar.png" TabIndex="15" />
                    <asp:CalendarExtender ID="CalendarExtender6" runat="server" TargetControlID="txtS1ExpDate" PopupButtonID="cmdS1ExpDate" Format="dd/MM/yyyy">
                    </asp:CalendarExtender>
                </td>
                <td>
                    <asp:DropDownList ID="cboS1ExpenseItem" runat="server" Width="200px" 
                        onselectedindexchanged="cboS1ExpenseItem_SelectedIndexChanged" 
                        AutoPostBack="True" TabIndex="16">
                    </asp:DropDownList>
                </td>
                <td>
                    <asp:TextBox ID="txtS1ExpAmt" runat="server" Width="78px" ontextchanged="txtS1ExpAmt_TextChanged" TabIndex="18" AutoPostBack="True"></asp:TextBox>
                </td>
                <td>
                    <asp:TextBox ID="txtS1ExpGST" runat="server" Width="78px" TabIndex="19"></asp:TextBox>
                </td>
                <td>
                <asp:TextBox ID="txtS1ExpOC" runat="server" Width="78px" 
                        ontextchanged="txtS1ExpOC_TextChanged" TabIndex="20" AutoPostBack="True"></asp:TextBox>
                </td>
                <td>
                    <asp:Button ID="cmdAddSection1Exp" runat="server" Text="Add" Width="80px" 
                        onclick="cmdAddSection1Exp_Click" TabIndex="21" /></td>
            </tr>
            <tr>
                <td colspan="6">
                    <table>
                        <tr>
                            <td class="HdrGnrl tRt" style="width:105px;">Sub item</td>
                            <td style="width:220px;">
                                <asp:DropDownList ID="cboS1ExpenseSubItem" runat="server" Width="200px" 
                                    TabIndex="17">
                                </asp:DropDownList>
                            </td>
                            <td style="width:85px;"></td>
                            <td style="width:85px;"></td>
                            <td style="width:85px;"></td>
                            <td style="width:100px;"></td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="txtS1ExpAmt" EventName="TextChanged" />
        <asp:AsyncPostBackTrigger ControlID="txtS1ExpOC" EventName="TextChanged" />
        <asp:AsyncPostBackTrigger ControlID="cboS1ExpenseItem" EventName="SelectedIndexChanged" />
    </Triggers>
</asp:UpdatePanel>
<asp:UpdatePanelAnimationExtender ID="UpdatePanelAnimationExtender4" TargetControlID="pnls1FieldUpdate" runat="server">
    <Animations>
        <OnUpdating>
            <Sequence>
                <FadeOut AnimationTarget="pnlExpense" minimumOpacity=".2" />
            </Sequence>
        </OnUpdating>
        <OnUpdated>
            <Sequence>
                <FadeIn AnimationTarget="pnlExpense" minimumOpacity=".2" />
            </Sequence>
        </OnUpdated>
    </Animations>
</asp:UpdatePanelAnimationExtender>

Why are all of the updatepanels updating when they shouldnt?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

⒈起吃苦の倖褔2024-12-07 05:42:01

在您发布的代码中,只有一个 UpdatePanel

但是,请注意 ChildrenAsTriggers 属性 默认设置为 true,因此将自动为该控件内的每个控件添加 AsyncPostBackTrigger 更新面板。所以我要尝试的第一件事是将其设置为 false :

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

Within the code you post, there is only one UpdatePanel.

However, please note than the ChildrenAsTriggers Property is set to true by default, so a AsyncPostBackTrigger will be added automatically for every control that is inside the UpdatePanel. So first thing I would try is to set it to false :

<asp:UpdatePanel ID="pnls1FieldUpdate" 
                 runat="server" 
                 UpdateMode="Conditional"
                 ChildrenAsTriggers="false" >
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文