Default.aspx page: First pull a ScriptManager control to the page, and then pull a UpdatePanel control. UpdatePanel inside a label to display the time, put a timer control to control the time update. Note that the label and label are placed inside the UpdatePanel control. Finally, the timer control's Interval property is set to 1000, allowing it to be updated every 1 seconds.
Default.aspx.cs page: Just in
protected void Page_Load (object sender, EventArgs e)
Inside input
Label1.Text = DateTime.Now.ToString ();
Can.
Here are two pages of source code:
Default.aspx
Copy Code code as follows:
<%@ Page language= "C #" autoeventwireup= "true" codebehind= "Default.aspx.cs" inherits= "dynamically displays real-time time. _default"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> dynamic display of real-time time </title>
<style type= "Text/css" >
. style1
{
height:183px;
}
</style>
<body>
<form id= "Form1" runat= "Server" >
<div> <asp:scriptmanager id= "ScriptManager1" runat= "Server" >
</asp:ScriptManager>
</div>
<table style= "Position:absolute; margin-left:200px; margin-right:200px; margin-top:100px; width:270px; height:78px; top:15px; left:10px; " >
<tr>
<td> dynamic display of real-time time </td>
</tr>
<TR><TD class= "Style1" ><asp:updatepanel id= "UpdatePanel1" runat= "Server" >
<ContentTemplate>
The current time is:
<asp:label id= "Label1" runat= "Server" text= "Label" ></asp:Label>
<asp:timer id= "Timer1" runat= "Server" interval= "1000" >
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
</td></tr>
</table>
</form>
</body>
Default.aspx.cs
Copy Code code as follows:
Using System;
Using System.Collections;
Using System.Configuration;
Using System.Data;
Using System.Linq;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.HtmlControls;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Xml.Linq;
namespace dynamic display of real-time time
{
public partial class _default:system.web.ui.page
{
protected void Page_Load (object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString ();
}
}
}