AJAX Timer控件的使用

来源:互联网 发布:wow for mac 国服 编辑:程序博客网 时间:2024/05/21 22:40

范例代码:

.aspx文件代码:

<form id="bodyForm" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="up_Body" runat="server">
    <ContentTemplate>
        <asp:Label ID="lbl_ShowTime" runat="server"></asp:Label>

   </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="tmr_Test" EventName="Tick" />
    </Triggers>
</asp:UpdatePanel>
<asp:Timer ID="tmr_Test" runat="server" Interval="5000" OnTick="tmr_Test_Tick">
</asp:Timer>   
</div>
</form>

.aspx.cs文件代码:

protected void Page_Load(object sender, EventArgs e)
    {

    }

protected void tmr_Test_Tick(object sender, EventArgs e)
    {
        lbl_ShowTime.Text = "服务器现在时间是:" + DateTime.Now.ToString();
    }

在web.config文件中配置对AJAX的支持即可!

原创粉丝点击