Default. aspx page: first pull a ScriptManager control to the page, and then pull an UpdatePanel control. Put a Label in UpdatePanel to display the time, and put a timer control to control the update of the time. Note that both the Label and Label must be placed in the UpdatePanel control. Finally, set the Interval attribute of the timer control to 1000 so that it can be executed once every one second, that is, the update time.
Default. aspx. cs page:
Protected void Page_Load (object sender, EventArgs e)
Enter
Label1.Text = DateTime. Now. ToString ();
You can.
The source code of the two pages is as follows:
Default. aspx
Copy codeThe Code is as follows: <% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "Default. aspx. cs" Inherits = "dynamic display of real-time. _ Default" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> dynamic display of real-time </title>
<Style type = "text/css">
. Style1
{
Height: 183px;
}
</Style>
</Head>
<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 </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>
</Html>
Default. aspx. csCopy codeThe Code is 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;
Dynamic Display of real-time namespace
{
Public partial class _ Default: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
Label1.Text = DateTime. Now. ToString ();
}
}
}