|
Default.ASPx.cs頁(yè)面:只需在
protected void Page_Load(object sender, EventArgs e)
里面輸入
Label1.Text = DateTime.Now.ToString();
即可。
下面是兩個(gè)頁(yè)面的源碼:
Default.ASPx
復(fù)制代碼 代碼如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.ASPx.cs" Inherits="動(dòng)態(tài)顯示實(shí)時(shí)時(shí)間._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>動(dòng)態(tài)顯示實(shí)時(shí)時(shí)間</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>動(dòng)態(tài)顯示實(shí)時(shí)時(shí)間</td>
</tr>
<tr><td class="style1"><ASP:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
當(dāng)前時(shí)間是:
<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.cs
復(fù)制代碼 代碼如下:
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 動(dòng)態(tài)顯示實(shí)時(shí)時(shí)間
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();
}
}
}
AspNet技術(shù):asp.net 實(shí)現(xiàn)動(dòng)態(tài)顯示當(dāng)前時(shí)間(不用javascript不考慮開(kāi)銷(xiāo)),轉(zhuǎn)載需保留來(lái)源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。