(转)
default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<br />
<asp:Label ID="Label1" runat="server" Text="Label" Width="209px"></asp:Label><br />
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label2" runat="server" Text="Label" Width="205px"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
<br />
<br />
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="Label" Width="199px"></asp:Label><br />
<br />
</div>
</form>
</body>
</html>
cs
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();
Label2.Text = DateTime.Now.ToString();
Label3.Text = DateTime.Now.ToString();
}
此代码为:Lable和button都在updateplan中.
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<br />
<asp:Label ID="Label1" runat="server" Text="Label" Width="209px"></asp:Label><br />
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label2" runat="server" Text="Label" Width="205px"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" /><br />
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="Label" Width="199px"></asp:Label><br />
<br />
</div>
</form>
以上代码为button在UpdatePanel外.以上2个为同一个效果.