首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >仅刷新另一个UpdatePanel中的UpdatePanel

仅刷新另一个UpdatePanel中的UpdatePanel
EN

Stack Overflow用户
提问于 2012-08-07 18:25:20
回答 4查看 18.9K关注 0票数 5

如果在另一个UpdatePanel中有UpdatePanel,并且在内部UpdatePanel中有一个按钮,我希望当单击此按钮时,只刷新内部UpdatePanel。怎么做到的?

EN

回答 4

Stack Overflow用户

发布于 2012-08-07 18:28:00

在innerupdate面板中,将updatemode设置为conditional,并将outerupdatepanel childrenastriggers属性设置为false。在内部更新面板中,添加一个回发触发器,并将其设置为将导致回发的按钮。像这样的东西

代码语言:javascript
复制
  <asp:UpdatePanel ID="parentup" runat="server" ChildrenAsTriggers="false">
    <ContentTemplate>
        <asp:UpdatePanel ID="chidlup" UpdateMode="Conditional" runat="server">
            <ContentTemplate>
                <asp:Button ID="btn" runat="server" />
            </ContentTemplate>
            <Triggers>
                <asp:PostBackTrigger ControlID="btn" />
            </Triggers>
        </asp:UpdatePanel>
    </ContentTemplate>
</asp:UpdatePanel>
票数 6
EN

Stack Overflow用户

发布于 2012-08-14 04:57:08

@Waqar Janjua是对的。

但您不必将ChildrenAsTriggers设置为false,有时保留为true会更方便。

在两个ChildrenAsTriggers面板中设置属性UpdateMode="Conditional" (保留updatepanel的默认设置为true)。然后在:之间添加触发器到您的按钮,如Janjua所说:

代码语言:javascript
复制
<Triggers>
    <asp:AsyncPostBackTrigger ControlID="btn" />
</Triggers>

当UpdateMode不是有条件的时候,每个更新面板都会更新它。

票数 5
EN

Stack Overflow用户

发布于 2015-05-23 14:53:09

这段代码可以帮助您:下面是Source

代码语言:javascript
复制
 <asp:ScriptManager ID="script1" runat="server"></asp:ScriptManager>
        <asp:UpdatePanel ID="up1" runat="server">
            <ContentTemplate>
                <asp:Label ID="lblTime" runat="server" ForeColor="Red"></asp:Label>
                <asp:Button ID="buttonOuter" runat="server" OnClick="buttonOuter_Click" Text="What is the time?" />
                <asp:UpdatePanel ID="up2" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>
                        <asp:Label ID="lblTime2" runat="server" ForeColor="Blue"></asp:Label>
                        <asp:Button ID="buttonInner" runat="server" OnClick="buttonInner_Click" Text="What is the time?" />
                    </ContentTemplate>
                </asp:UpdatePanel>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger  ControlID="buttonOuter" EventName="Click"/>
            </Triggers>
        </asp:UpdatePanel>

这是code behinde

代码语言:javascript
复制
 protected void Page_Load(object sender, EventArgs e)
{

}
protected void buttonInner_Click(object sender, EventArgs e)
{
    up2.Update();
    lblTime2.Text = DateTime.Now.Second.ToString();
}
protected void buttonOuter_Click(object sender, EventArgs e)
{
    lblTime.Text = DateTime.Now.Second.ToString();
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11843912

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档