代码之家  ›  专栏  ›  技术社区  ›  Brad8118

无法更新第二个更新面板

  •  4
  • Brad8118  · 技术社区  · 14 年前

    我的页面上有3个更新面板,我希望其中2个在触发事件时更新。在其中一个更新面板中,我有一个ASP ReoderList。

    <asp:UpdatePanel ID="upMain" UpdateMode="Conditional" runat="server" style="left: 0px; top: 0px; min-height: 100px; width: 495px; overflow: auto;">
                    <ContentTemplate>
                        <div class="reorderListDemo" style="position: relative; left: -41px; width: 490px; overflow: auto;">
                            <ajax:ReorderList ID="rlAlerts" Style="min-height: 100px; padding: 0px 6px 0px 0px;" Width="480px" runat="server" PostBackOnReorder="false" CallbackCssStyle="callbackStyle" DragHandleAlignment="Left" DataKeyField="ItemID" SortOrderField="Priority" OnItemReorder="rlAlerts_ItemReorder">
                                <ItemTemplate>
                                    <%--set the class to inactiveAlert if the active flag is set to false--%>
                                    <div id="alertItem<%# Eval("ItemID")%>" class="<%# Convert.ToBoolean(Eval("Active")) ? "" : "inactiveAlert" %>" onclick="updateAlertPreview('<%# Eval("ItemID")%>','<%# Eval("Priority")%>','<%# Eval("Title") %>','<%# Eval("Description") %>', '<%# Eval("StartDate") %>', '<%# Eval("EndDate")  %>', '<%# Eval("Image") %>');">
                                        <div style="position: relative; float: left; left: 10px; padding-top: 6px; overflow: hidden; width: 180px; height: 17px;">
                                            <asp:Label ID="Label4" runat="server" Text='<%# HttpUtility.HtmlEncode(Convert.ToString(Eval("Title"))) %>' />
                                        </div>
                                     </div>
                                </ItemTemplate>
                                <ReorderTemplate>
                                    <asp:Panel ID="Panel2" runat="server" CssClass="reorderCue" />
                                </ReorderTemplate>
                                <DragHandleTemplate>
                                    <div class="dragHandle">
                                    </div>
                                </DragHandleTemplate>
                            </ajax:ReorderList>
                        </div>
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="rlAlerts" EventName="ItemReorder" />
                        <asp:AsyncPostBackTrigger ControlID="ckbxShowInactive" EventName="CheckedChanged" />
                    </Triggers>
                </asp:UpdatePanel>
    

    当前,此更新面板将更新项目或重新排序或复选框状态更改。 现在我有了第二个更新面板,它在重新排序列表时不会更新。

    <asp:UpdatePanel ID="UpdatePanelAlertOrderNotification" UpdateMode="Conditional" runat="server">
                        <ContentTemplate>
                            <asp:Label ID="lblOrderChangedNotification" runat="server"></asp:Label>
                        </ContentTemplate>
                        <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="rlAlerts" EventName="ItemReorder" />
                        </Triggers>
                    </asp:UpdatePanel>
    

    下面是我的代码:

        protected void rlAlerts_ItemReorder(object sender, AjaxControlToolkit.ReorderListItemReorderEventArgs e)
            {
               .....
               Session["AlertOrderChangedNotification"] = Resources.LocalizedText.Alert_Order_Changed;
    
                lblOrderChangedNotification.Text = "AWESOME";
                //lblOrderChangedNotification.DataBind();
                //UpdatePanelAlertOrderNotification.Update();
    }
    

    我已经完成了这段代码,我不明白它为什么不能工作。

    我累的事情: 我累了: 将UpdatePanelAlertOrderNotification的UpdateMode设置为Always。 若要将UpdatePanelAlertOrderNotification的UpdateMode设置为Conditional,请移除其触发器并让代码隐藏函数更新 直接更新面板。 在会话中存储文本,并在页面帖子触发时检查会话中是否有文本。我可以在页面加载中跳过此代码 但它仍然不起作用。(两行都被注释掉,然后只有1行,然后没有一行被注释掉。)

    protected void Page_Load(object sender, EventArgs e)
            {
                if (Session["AlertOrderChangedNotification"] != null)
                {
                    lblOrderChangedNotification.Text = Session["AlertOrderChangedNotification"] as string;
                    //lblOrderChangedNotification.DataBind();
                    //UpdatePanelAlertOrderNotification.Update();
                }
            }
    

    我不知道我是否有问题,因为我有两个具有相同触发器的更新面板(即使 我尝试从UpdatePanelAlertOrderNotification中删除它,并将其设置为Always。)

    Changs: 所以我尝试添加一个新按钮并让更新面板更新。这是可行的。如果我将触发器切换回重新排序列表,它将不起作用。所以我的问题是,我可以有两个不同的updatepanels具有相同的触发器吗?如果我不能,我应该可以通过调用updatePanelAlertOrderNotification.update()来进行中断的一次更新?想法?

    <div style="position: absolute; top: 195px; right: 10px; height: 100px; width: 120px; overflow: hidden;">
                        <asp:UpdatePanel ID="UpdatePanelAlertOrderNotification" UpdateMode="Conditional" runat="server">
                            <ContentTemplate>
                                <asp:Label ID="lblOrderChangedNotification" runat="server"></asp:Label>
                            </ContentTemplate>
                            <Triggers>
                                <%--<asp:AsyncPostBackTrigger ControlID="rlAlerts" EventName="ItemReorder" />--%>
                                <asp:AsyncPostBackTrigger ControlID="btnUpdateBrokenUpdatePanel" EventName="Click" />
                            </Triggers>
                        </asp:UpdatePanel>
                        <div style="position: relative; top: 25px; left: 10px;">
                            <asp:Button ID="btnUpdateBrokenUpdatePanel" runat="server" CssClass="redButton" Width="300px" Height="25px" Text="Update Broken UPdatePanel" OnClick="btnUpdateBrokenUpdatePanel_Click" />
                        </div>
    

    任何帮助都是了不起的。 谢谢Brad

    2 回复  |  直到 14 年前
        1
  •  0
  •   Mitchel Sellers    14 年前

    我猜您对更新面板没有得到适当的通知有问题,我将用条件触发器设置包装面板,然后让它对其他面板调用update方法。

    您要确保的一件事是,实际更新这些项显示的代码也会被执行。

        2
  •  0
  •   Fadrian Sudaman    14 年前

    您遇到的问题是,控件rlalerts位于第一个更新面板的内容模板中,当您在第二个更新面板中定义异步触发器时,它不知道rlalerts,因为它已经预先准备了第一个更新面板中的命名容器。

    尝试以下方法之一:

    • 如果可能的话,将rlalerts置于updatepanel之外
    • 在itemReorder事件处理程序的代码隐藏中,显式调用updatePanelAlertOrderNotification.update()。听起来你试过了,但不管用,这很奇怪
    • 在prerender上显式注册第二个updatepanel的代码隐藏触发器:

      updatePanelAlertOrderNotification.triggers.add(new asyncPostbackTrigger()) controlID=rlalerts.uniqueid,eventname=“itemReorder”);