如果在另一个UpdatePanel中有UpdatePanel,并且在内部UpdatePanel中有一个按钮,我希望当单击此按钮时,只刷新内部UpdatePanel。怎么做到的?
发布于 2012-08-07 18:28:00
在innerupdate面板中,将updatemode设置为conditional,并将outerupdatepanel childrenastriggers属性设置为false。在内部更新面板中,添加一个回发触发器,并将其设置为将导致回发的按钮。像这样的东西
<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>发布于 2012-08-14 04:57:08
@Waqar Janjua是对的。
但您不必将ChildrenAsTriggers设置为false,有时保留为true会更方便。
在两个ChildrenAsTriggers面板中设置属性UpdateMode="Conditional" (保留updatepanel的默认设置为true)。然后在:之间添加触发器到您的按钮,如Janjua所说:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btn" />
</Triggers>当UpdateMode不是有条件的时候,每个更新面板都会更新它。
发布于 2015-05-23 14:53:09
这段代码可以帮助您:下面是Source
<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
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();
}https://stackoverflow.com/questions/11843912
复制相似问题