asp.net 實(shí)現(xiàn)動(dòng)態(tài)顯示當(dāng)前時(shí)間(不用javascript不考慮開銷)
更新時(shí)間:2009年11月03日 23:50:39 作者:
asp.net實(shí)現(xiàn)動(dòng)態(tài)顯示時(shí)間,無需用到j(luò)avascrip,而是用了AJAX。
Default.aspx頁面:先拉一個(gè)ScriptManager控件到頁面,然后拉一個(gè)UpdatePanel控件。UpdatePanel里面放一個(gè)Label用于顯示時(shí)間,放一個(gè)timer控件用于控制時(shí)間的更新。注意Label與Label都要放到UpdatePanel控件里面。最后,timer控件的Interval屬性設(shè)置為1000,讓它每1秒執(zhí)行一次即更新時(shí)間。
Default.aspx.cs頁面:只需在
protected void Page_Load(object sender, EventArgs e)
里面輸入
Label1.Text = DateTime.Now.ToString();
即可。
下面是兩個(gè)頁面的源碼:
Default.aspx
<%@ 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
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();
}
}
}
Default.aspx.cs頁面:只需在
protected void Page_Load(object sender, EventArgs e)
里面輸入
Label1.Text = DateTime.Now.ToString();
即可。
下面是兩個(gè)頁面的源碼:
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();
}
}
}
您可能感興趣的文章:
- 純JS實(shí)現(xiàn)動(dòng)態(tài)時(shí)間顯示代碼
- JS動(dòng)態(tài)獲取當(dāng)前時(shí)間,并寫到特定的區(qū)域
- html+js實(shí)現(xiàn)動(dòng)態(tài)顯示本地時(shí)間
- Java從服務(wù)器上獲取時(shí)間動(dòng)態(tài)顯示在jsp頁面實(shí)現(xiàn)思路
- javascript頁面動(dòng)態(tài)顯示時(shí)間變化示例代碼
- .net動(dòng)態(tài)顯示當(dāng)前時(shí)間(客戶端javascript)
- JS動(dòng)態(tài)日期時(shí)間的獲取方法
- js顯示動(dòng)態(tài)時(shí)間的方法詳解
- 基于javascript實(shí)現(xiàn)動(dòng)態(tài)顯示當(dāng)前系統(tǒng)時(shí)間
- 純js實(shí)現(xiàn)動(dòng)態(tài)時(shí)間顯示
相關(guān)文章
.NET Core應(yīng)用類型(Portable apps & Self-contained apps)
這篇文章主要介紹了.NET Core應(yīng)用類型,通常類型用來描述一個(gè)特定的執(zhí)行模型或者基于此的應(yīng)用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04
ASP.NET中iframe框架點(diǎn)擊左邊頁面鏈接 右邊顯示鏈接頁面內(nèi)容
這篇文章主要介紹了ASP.NET中iframe框架點(diǎn)擊左邊頁面鏈接,右邊顯示鏈接頁面內(nèi)容的實(shí)現(xiàn)代碼,感興趣的小伙伴們可以參考一下2016-07-07
ASP.NET下母版頁和內(nèi)容頁中的事件發(fā)生順序整理
母版頁與內(nèi)容頁合并后事件的發(fā)生順序,有需要區(qū)別的朋友能用的到2009-03-03
jQuery+Asp.Net實(shí)現(xiàn)省市二級(jí)聯(lián)動(dòng)功能的方法
這篇文章主要介紹了jQuery+Asp.Net實(shí)現(xiàn)省市二級(jí)聯(lián)動(dòng)功能的方法,涉及asp.net數(shù)據(jù)庫讀取與字符串轉(zhuǎn)換相關(guān)操作技巧,需要的朋友可以參考下2017-05-05
asp.net下用url重寫URLReWriter實(shí)現(xiàn)任意二級(jí)域名的方法
asp.net下用url重寫URLReWriter實(shí)現(xiàn)任意二級(jí)域名的方法...2007-03-03
ASP.NET 導(dǎo)出到Excel時(shí)保留換行的代碼
由于Excel畢竟不是 HTML,它有自己的樣式標(biāo)準(zhǔn),在Excel 中,實(shí)現(xiàn)換行的方法是2008-12-12
Asp.Net Core2.1前后使用HttpClient的兩種方式
這篇文章主要給大家介紹了關(guān)于Asp.Net Core2.1前后HttpClient的使用方式,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-03-03

