updatepanel.update问题

时间:2012-09-29 20:38:34

标签: c# asp.net updatepanel

我有两个嵌套的updatepanels我从源代码更新面板但没有任何生效。代码如下

<div style="display:block; clear: left;" runat="server" id="DivLike">
    <asp:UpdatePanel ID="UpdatePanelLike" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <div style="position: relative;">
                <div style="position: absolute; top: 0px; left: 0px;">
                    <asp:LinkButton ID="LinkButtonLike" runat="server" CommandName='<%#Eval("Like_Command") %>'
                    Font-Size="XX-Small" OnCommand="LinkButton2_Command" Text='<%#Eval("Like_Command")%>'></asp:LinkButton>
                </div>
                <div class="popupstyle" style="position:absolute; top:0px; left:0px; display:none;"
                id="DivChapters" runat="server">
                    <asp:UpdatePanel ID="UpdatePanelLinkActivity" runat="server" UpdateMode="Conditional">
                        <ContentTemplate>
                            <div>Select Chapter:
                                <asp:DropDownList ID="DropDownListChapters" runat="server"
                                AutoPostBack="true" OnSelectedIndexChanged="DropDownListChapters_SelectedIndexChanged"></asp:DropDownList>
                            </div>
                            <div>Select Topic:
                                <asp:DropDownList ID="DropDownListTopics" runat="server"></asp:DropDownList>
                            </div>
                            <div>
                                <asp:LinkButton ID="LinkButtonAddLink" runat="server" OnCommand="LinkButtonAddLink_Command"
                                Text="Add" CssClass="UtilityClass"></asp:LinkButton>
                            </div>
                            <asp:UpdateProgress ID="UpdateProgressLinkActivity" runat="server" AssociatedUpdatePanelID="UpdatePanelLinkActivity"
                            DynamicLayout="True">
                                <ProgressTemplate>
                                    <div style=" position:absolute; top:50%; left:50%; background-color:white;"
                                    id="divLoading">
                                        <img src="Images/loading25.gif" alt="Loading..." style="" />
                                    </div>
                                </ProgressTemplate>
                            </asp:UpdateProgress>
                        </ContentTemplate>
                        <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="LinkButtonAddLink" EventName="Command"
                            />
                        </Triggers>
                    </asp:UpdatePanel>
                </div>
            </div>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="LinkButtonLike" EventName="Command"
            />
        </Triggers>
    </asp:UpdatePanel>
</div>

下面的代码后面更新了面板,但没有更新任何面板。虽然当我用调试器分析它时,每个东西都被完美地分配。

 protected void DropDownListChapters_SelectedIndexChanged(object sender, EventArgs e )
 {
    DropDownList DDL = (DropDownList)sender;
    DropDownListTopics.DataSource = ChapterDataAccess.GetUserTopics(Convert.ToInt32(DDL.SelectedItem.Value), new Guid(Membership.GetUser().ProviderUserKey.ToString()));
    DropDownListTopics.DataTextField = "Name";
    DropDownListTopics.DataValueField = "Id";
    DropDownListTopics.DataBind();
    ListItem item=new ListItem ("topics","value" );
    DropDownListTopics.Items.Add(item);
    UpdatePanel thepanel= (UpdatePanel)DDL.Parent.Parent;
    UpdatePanel theparentpanel=(UpdatePanel)DDL.Parent.Parent.Parent.Parent.Parent ;
    theparentpanel.Update();
    thepanel.Update();


}

1 个答案:

答案 0 :(得分:0)

我认为您没有正确访问更新面板..

当UpdatePanel未包含在其他内容占位符中时,我认为您可以直接访问更新面板而不是使用父级来查找它..

简单

UpdatePanelLinkActivity.Update();
UpdatePanelLike.Update() ;   

应该做..