<script language="c#">
protected void Button2_Click(object sender, EventArgs e)
{
this.textbox1.Text = DateTime.Now.ToString();
}
</script>
<atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"/>
<atlas:UpdatePanel ID="UpdatePanel1" runat="server" Mode="Conditional" RenderMode="inline">
<Triggers>
<atlas:ControlEventTrigger ControlID="Button1" EventName="Click"/></Triggers>
<ContentTemplate>
<asp:TextBox ID="textbox1" runat="server" ></asp:TextBox>
</ContentTemplate>
</atlas:UpdatePanel>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="click" />
執行這段程式,點選Button1後,文字框中的內容呈現為當前的時間。
UpdatePanel控制元件用放置需要更新或改變的控制元件,
UpdatePanel控制元件內可包含多個<Triggers>標記,但只能包含一個<ContentTemplate>標記
其中的<Triggers>標記的ControlEventTrigger的ControlID指改變textbox1的控制元件ID(這裡應填寫textbox1),EventName應填入控制元件所觸發的事件名,這裡的事件名等同於控制元件本身的事件名稱
在<ContentTemplate>內放置要改變的控制元件。
Mode屬性的設定
The Mode
property specifies when the UpdatePanel
refreshes its contents. If the Mode
property is set to Always
, the contents of the panel are refreshed during every postback. If the Mode
property is set to Conditional
, the panel is rendered on the server based on one or more triggers, such as when specified property values change or when specified events occur. This optimizes the markup sent to the client during postback.