asp.net implement dynamic display of current time (without JavaScript regardless of overhead) _ Practical Tips

Source: Internet
Author: User
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>
&LT;TR&GT;&LT;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 ();
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.