頁面部分
復制代碼 代碼如下:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<h2>
使用VS控件updatePanel實現無刷新
</h2>
<p>
<asp:UpdatePanel ID="UpdatePanel1" RenderMode="Block" UpdateMode="Conditional" runat="server">
<ContentTemplate>
點擊按鈕從服務器獲取當前時間<asp:TextBox ID="txtTime" runat="server"></asp:TextBox>
<asp:Button ID="btn1" runat="server" Text="Button" onclick="btn1_Click" />
</ContentTemplate>
<Triggers>
<%--<asp:PostBackTrigger ControlID="btn1" />--%>
<asp:AsyncPostBackTrigger ControlID="btn1"/>
</Triggers>
</asp:UpdatePanel>
</p>
後台代碼
復制代碼 代碼如下:
protected void btn1_Click(object sender, EventArgs e)
{
txtTime.Text = DateTime.Now.ToString();
}