71.C# ASP.NET - Ajax를 이용한 시간 출력
FrmTimer.aspx |
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">
<title></title> </head> <body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
타이머 컨트롤<hr />
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> 현재시간 : <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick"> </asp:Timer> </ContentTemplate>
</asp:UpdatePanel>
<br />
</div>
</form> </body> </html> |
FrmTimer.aspx.cs |
protected void Timer1_Tick(object sender, EventArgs
e) {
// 지정된 시간마다 현재 이벤트 핸들러 실행
this.Label1.Text = DateTime.Now.ToLongTimeString(); } |
결과화면 |
[그림71-1] |