简单的 Ajax 程序需要在单击按钮时更新单个更新面板,两者都可以。这是更新的代码,
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" ChildrenAsTriggers="false"
runat="server">
<ContentTemplate>
<fieldset style="width: 30%">
<legend>Panel - 1 </legend>
<asp:Label ID="label1" runat="server"></asp:Label>
<asp:Button ID="b1" runat="server" OnClick="both" Text="Update Both Pannels" />
<asp:Button ID="b2" runat="server" OnClick="one" Text="Update Single Pannel" />
</fieldset>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="b1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
<ContentTemplate>
<fieldset style="width: 30%">
<legend>Panel - 2 </legend>
<asp:Label ID="label2" runat="server"></asp:Label>
</fieldset>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="b2" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
按钮点击事件如下,
protected void both(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToLongTimeString();
label2.Text = DateTime.Now.ToLongTimeString();
UpdatePanel2.Update();
}
protected void one(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToLongTimeString();
label2.Text = DateTime.Now.ToLongTimeString();
UpdatePanel2.Update();
}
输出保持不变..提前谢谢...