ScriptManager和timer的应用 给个学习网址就行 我没用过的qq卡ScriptManager而后者要求使用前者

AJAX/JavaScript(23)
新瓶旧酒ASP.NET AJAX(1) - 简单地过一下每个控件(ScriptManager、ScriptManagerProxy、UpdatePanel、 UpdateProgress和Timer)
ASP.NET AJAX就5个控件,分别是ScriptManager、ScriptManagerProxy、UpdatePanel、UpdateProgress和Timer。先简单地过一下。
1、ScriptManager 和ScriptManagerProxy
&&& ·一个页只能有一个ScriptManager(包含了所有脚本资源),要放到任何用到AJAX的控件的前面。
&&& ·如果把它放到母版页,而内容页需要与其不同的配置的话,则应在内容页使用ScriptManagerProxy。
&&& ·ScriptManager默认EnablePartialRendering="true"。
&&& ·ScriptManager的 AllowCustomErrorsRedirect="true"的时候,出现异常就会转到web.config里customErrors中defaultRedirect所指的地址。
2、 UpdatePanel
&&& ·UpdatePanel内放置需要被刷新的控件,如果是其内部控件事件导致其刷新,则不用另外做什么设置,因为UpdatePanel默认ChildrenAsTriggers="true"。
&&& ·如果是UpdatePanel外部控件导致其刷新的话,则应设置 Triggers。
&&& ·在Triggers内,如果AsyncPostBackTrigger未设置EventName,则为其指定控件的默认事件。
&&& ·UpdatePanel默认UpdateMode="Always",需要的话应设置UpdateMode="Conditional"。
&&& ·RenderMode="Block"对应div;RenderMode="Inline"对应span
3、UpdateProgress
&&& ·默认,任何回发,当有延迟的时候则显示UpdateProgress里的ProgressTemplate。
&&& ·要与某UpdatePanel关联则设置 AssociatedUpdatePanelID属性。
&&& ·DynamicLayout为true则用“display:”隐藏;DynamicLayout为false则用 “visibility:”隐藏。
&&& ·默认情况下,例如有2个异步回发,如果第1个还没有执行完毕就执行第2个的话,则会先取消第1个异步回发。
&&& ·Interval:间隔时间,单位(毫秒);每一个间隔时间后将触发 Tick事件。
&&& ·Timer要放在其所刷新的UpdatePanel内部;放外面的话要设置UpdatePanel的Triggers。
&&& ·要在UpdatePanel中使用Validator的话,请参看
&&& ·内容页获取母版页的ScriptManager:ScriptManager.GetCurrent(Page)
&&& ·后置代码处对UpdatePanel编程,例: ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(this.Button1); ScriptManager.GetCurrent (this).RegisterPostBackControl(this.Button2); this.UpdatePanel1.Update();
&&& ·
&&& ·
&&& ·
1、最简单的示例
&%@&Page&Language="C#"&MasterPageFile="~/Site.master"&AutoEventWireup="true"&CodeFile="Sample.aspx.cs"
&&&&Inherits="Overview_Sample"&Title="最简单的示例"&%&
&asp:Content&ID="Content1"&ContentPlaceHolderID="ContentPlaceHolder1"&runat="Server"&
&&&&&&&&&li&之前要有ScriptManager(包含了所有脚本资源),我把它放到母版页了。内容页如需不同配置则应使用ScriptManagerProxy。&/li&
&&&&&&&&&li&最简单的示例,拖个UpdatePanel进来。在 UpdatePanel内拖个GridView,并设置其数据源即可。&&/li&
&&&&&asp:UpdatePanel&ID="UpdatePanel1"&runat="server"&
&&&&&&&&&ContentTemplate&
&&&&&&&&&&&&&asp:GridView&ID="GridView1"&runat="server"&AllowPaging="True"&AllowSorting="True"
&&&&&&&&&&&&&&&&DataSourceID ="SqlDataSource1"&
&&&&&&&&&&&&&&&&&Columns&
&&&&&&&&&&&&&&&&&&&&&asp:CommandField&ShowEditButton="True"&ShowSelectButton="True"&/&
&&&&&&&&&&&&&&&&&/Columns&
&&&&&&&&&&&&&/asp:GridView&
&&&&&&&&&/ContentTemplate&
&&&&&/asp:UpdatePanel&
&&&&&asp:SqlDataSource&ID="SqlDataSource1"&runat="server"&ConnectionString="&% $&ConnectionStrings:connstr&%&"
&&&&&&&&DeleteCommand="DELETE&FROM&[Products]&WHERE&[ProductID]&=&@ProductID"&InsertCommand="INSERT&INTO&[Products]& ([ProductName],&[QuantityPerUnit],&[UnitPrice],&[Discontinued])&VALUES& (@ProductName,&@QuantityPerUnit,&@UnitPrice,&@Discontinued)"
&&&&&&&&SelectCommand="SELECT& [ProductID],&[ProductName],&[QuantityPerUnit],&[UnitPrice],&[Discontinued]&FROM& [Products]"
&&&&&&&&UpdateCommand="UPDATE& [Products]&SET&[ProductName]&=&@ProductName,&[QuantityPerUnit]&=&@QuantityPerUnit,& [UnitPrice]&=&@UnitPrice,&[Discontinued]&=&@Discontinued&WHERE&[ProductID] &=&@ProductID"&
&&&&&&&&&DeleteParameters&
&&&&&&&&&&&&&asp:Parameter&Name="ProductID"&Type="Int32"&/&
&&&&&&&&&/DeleteParameters&
&&&&&&&&&UpdateParameters&
&&&&&&&&&&&&&asp:Parameter&Name="ProductName"&Type="String"&/&
&&&&&&&&&&&&&asp:Parameter&Name="QuantityPerUnit"&Type="String"&/&
&&&&&&&&&&&&&asp:Parameter&Name="UnitPrice"&Type="Decimal"&/&
&&&&&&&&&&&&&asp:Parameter&Name="Discontinued"&Type="Boolean"&/&
&&&&&&&&&&&&&asp:Parameter&Name="ProductID"&Type="Int32"&/&
&&&&&&&&&/UpdateParameters&
&&&&&&&&&InsertParameters&
&&&&&&&&&&&&&asp:Parameter&Name="ProductName"&Type="String"&/&
&&&&&&&&&&&&&asp:Parameter&Name="QuantityPerUnit"&Type="String"&/&
&&&&&&&&&&&&&asp:Parameter&Name="UnitPrice"&Type="Decimal"&/&
&&&&&&&&&&&&&asp:Parameter&Name="Discontinued"&Type="Boolean"&/&
&&&&&&&&&/InsertParameters&
&&&&&/asp:SqlDataSource&
&/asp:Content&
2、UpdatePanel
&%@&Page&Language="C#"&MasterPageFile="~/Site.master"&AutoEventWireup="true"&CodeFile="UpdatePanel.aspx.cs"
&&&&Inherits="Overview_UpdatePanel"&Title="UpdatePanel"&%&
&asp:Content&ID="Content1"&ContentPlaceHolderID="ContentPlaceHolder1"&runat="Server"&
&&&&&&&&&li&UpdatePanel内放置需要被刷新的控件,如果是其内部控件事件导致其刷新,则不用另外做什么设置,因为UpdatePanel默认ChildrenAsTriggers="true"。&/li&
&&&&&&&&&li&如果是UpdatePanel外部控件导致其刷新的话,则应设置Triggers。&/li&
&&&&&&&&&li&在Triggers内,如果AsyncPostBackTrigger 未设置EventName,则为其指定控件的默认事件。&/li&
&&&&&&&&&li&UpdatePanel默认UpdateMode="Always",需要的话应设置UpdateMode="Conditional"。&/li&
&&&&&&&&&li&RenderMode="Block"对应div; RenderMode="Inline"对应span&/li&
&&&&&asp:UpdatePanel&ID="UpdatePanel1"&runat="server"&
&&&&&&&&&contenttemplate&
&&&&&&&&&&&&&fieldset&
&&&&&&&&&&&&&&&&&legend&我在UpdatePanel里&/legend&
&&&&&&&&&&&&&&&&&asp:Label&ID="Label1"&runat="server"&Text="我是 Label"&&/asp:Label&
&&&&&&&&&&&&&/fieldset&
&&&&&&&&&/contenttemplate&
&&&&&&&&&triggers&
&&&&&&&&&&&&&%--如果没设置 EventName,则取默认事件,Button的默认事件为Click-- %&
&&&&&&&&&&&&&asp:AsyncPostBackTrigger&ControlID="Button1"&/&
&&&&&&&&&/triggers&
&&&&&/asp:UpdatePanel&
&&&&&&&&&&/p&
&&&&&fieldset&
&&&&&&&&&legend&我在UpdatePanel外&/legend&
&&&&&&&&&asp:Button&ID="Button1"&runat="server"&Text="按钮"&OnClick="Button1_Click"&/&
&&&&&/fieldset&
&&&&&&&&&&/p&
&&&&&%--嵌套UpdatePanel-- %&
&&&&&asp:UpdatePanel&ID="UpdatePanel2"&runat="server"&UpdateMode="Conditional"&
&&&&&&&&&contenttemplate&
&&&&&&&&&&&&&fieldset&
&&&&&&&&&&&&&&&&&legend&外围UpdatePanel&/legend&
&&&&&&&&&&&&&&&&&asp:Label&ID="Label2"&runat="server"&Text="我是 Label"&&/asp:Label&
&&&&&&&&&&&&&&&&&asp:Button&ID="Button2"&runat="server"&Text="按钮"&OnClick="Button2_Click"&/&
&&&&&&&&&&&&&&&&&asp:UpdatePanel&ID="UpdatePanel3"&runat="server"&
&&&&&&&&&&&&&&&&&&&&&ContentTemplate&
&&&&&&&&&&&&&&&&&&&&&&&&&fieldset&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&legend&嵌套UpdatePanel&/legend&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&asp:Label&ID="Label3"&runat="server"&Text="我是Label"&&/asp:Label&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&asp:Button&ID="Button3"&runat="server"&Text="按钮"&OnClick="Button3_Click"&/&
&&&&&&&&&&&&&&&&&&&&&&&&&/fieldset&
&&&&&&&&&&&&&&&&&&&&&/ContentTemplate&
&&&&&&&&&&&&&&&&&/asp:UpdatePanel&
&&&&&&&&&&&&&/fieldset&
&&&&&&&&&/contenttemplate&
&&&&&/asp:UpdatePanel&
&/asp:Content&
3、UpdateProgress
&%@&Page&Language="C#"&MasterPageFile="~/Site.master"&AutoEventWireup="true"&CodeFile="UpdateProgress.aspx.cs"
&&&&Inherits="Overview_UpdateProgress"&Title="UpdateProgress"&%&
&asp:Content&ID="Content1"&ContentPlaceHolderID="ContentPlaceHolder1"&runat="Server"&
&&&&&&&&&li&默认,任何回发,当有延迟的时候则显示 UpdateProgress里的ProgressTemplate。&/li&
&&&&&&&&&li&要与某UpdatePanel关联则设置 AssociatedUpdatePanelID属性。&/li&
&&&&&&&&&li&DynamicLayout为true则用“display: ”隐藏;DynamicLayout为false则用“visibility:”隐藏。&/li&
&&&&&&&&&li&默认情况下,例如有2个异步回发,如果第1 个还没有执行完毕就执行第2个的话,则会先取消第1个异步回发。&/li&
&&&&&asp:UpdatePanel&ID="UpdatePanel1"&runat="server"&
&&&&&&&&&ContentTemplate&
&&&&&&&&&&&&&fieldset&
&&&&&&&&&&&&&&&&&legend&UpdatePanel1&/legend&
&&&&&&&&&&&&&&&&&asp:Label&ID="Label1"&runat="server"&Text="Label1"&&/asp:Label&
&&&&&&&&&&&&&&&&&br&/&
&&&&&&&&&&&&&&&&&asp:Button&ID="Button1"&runat="server"&Text="Button"&OnClick="Button1_Click"&/&
&&&&&&&&&&&&&/fieldset&
&&&&&&&&&/ContentTemplate&
&&&&&/asp:UpdatePanel&
&&&&&asp:UpdateProgress&ID="UpdateProgress1"&runat="server"&AssociatedUpdatePanelID="UpdatePanel1"
&&&&&&&&DynamicLayout="false"&
&&&&&&&&&ProgressTemplate&
&&&&&&&&&&&&&p&
&&&&&&&&&&&&&&&&UpdatePanel1更新中
&&&&&&&&&&&&&/p&
&&&&&&&&&/ProgressTemplate&
&&&&&/asp:UpdateProgress&
&&&&&&&&&&/p&
&&&&&asp:UpdatePanel&ID="UpdatePanel2"&runat="server"&
&&&&&&&&&ContentTemplate&
&&&&&&&&&&&&&fieldset&
&&&&&&&&&&&&&&&&&legend&UpdatePanel2&/legend&
&&&&&&&&&&&&&&&&&asp:Label&ID="Label2"&runat="server"&Text="Label2"&&/asp:Label&
&&&&&&&&&&&&&&&&&br&/&
&&&&&&&&&&&&&&&&&asp:Button&ID="Button2"&runat="server"&Text="Button"&OnClick="Button2_Click"&/&
&&&&&&&&&&&&&/fieldset&
&&&&&&&&&/ContentTemplate&
&&&&&/asp:UpdatePanel&
&&&&&asp:UpdateProgress&ID="UpdateProgress2"&runat="server"&AssociatedUpdatePanelID="UpdatePanel2"
&&&&&&&&DynamicLayout="true"&
&&&&&&&&&ProgressTemplate&
&&&&&&&&&&&&&p&
&&&&&&&&&&&&&&&&UpdatePanel2更新中
&&&&&&&&&&&&&/p&
&&&&&&&&&/ProgressTemplate&
&&&&&/asp:UpdateProgress&
&&&&&&&&&&/p&
&&&&&asp:UpdatePanel&ID="UpdatePanel3"&runat="server"&
&&&&&&&&&ContentTemplate&
&&&&&&&&&&&&&fieldset&
&&&&&&&&&&&&&&&&&legend&UpdatePanel3&/legend&
&&&&&&&&&&&&&&&&&asp:Label&ID="Label3"&runat="server"&Text="Label3"&&/asp:Label&&br&/&
&&&&&&&&&&&&&&&&&asp:Button&ID="Button3"&runat="server"&Text="Button"&OnClick="Button3_Click"&/&
&&&&&&&&&&&&&/fieldset&
&&&&&&&&&/ContentTemplate&
&&&&&/asp:UpdatePanel&
&&&&&asp:UpdateProgress&ID="UpdateProgress3"&runat="server"&
&&&&&&&&&ProgressTemplate&
&&&&&&&&&&&&有延迟我就更新
&&&&&&&&&/ProgressTemplate&
&&&&&/asp:UpdateProgress&
&/asp:Content&
&%@&Page&Language="C#"&MasterPageFile="~/Site.master"&AutoEventWireup="true"&CodeFile="Timer.aspx.cs"
&&&&Inherits="Overview_Timer"&Title="Timer"&%&
&asp:Content&ID="Content1"&ContentPlaceHolderID="ContentPlaceHolder1"&runat="Server"&
&&&&&&&&&li&Interval:间隔时间,单位(毫秒);每一个间隔时间后将触发Tick事件&&/li&
&&&&&&&&&li&Timer要放在其所刷新的UpdatePanel内部;放外面的话要设置UpdatePanel的Triggers。&/li&
&&&&&asp:UpdatePanel&ID="UpdatePanel1"&runat="server"&
&&&&&&&&&ContentTemplate&
&&&&&&&&&&&&&fieldset&
&&&&&&&&&&&&&&&&&legend&UpdatePanel1&/legend&
&&&&&&&&&&&&&&&&&p&
&&&&&&&&&&&&&&&&&&&&内部Timer
&&&&&&&&&&&&&&&&&&&&&asp:Timer&ID="Timer1"&runat="server"&OnTick="Timer1_Tick"&Interval="1000"&
&&&&&&&&&&&&&&&&&&&&&/asp:Timer&
&&&&&&&&&&&&&&&&&/p&
&&&&&&&&&&&&&&&&&asp:Label&ID="Label1"&runat="server"&Text="Label"&&/asp:Label&
&&&&&&&&&&&&&/fieldset&
&&&&&&&&&/ContentTemplate&
&&&&&/asp:UpdatePanel&
&/asp:Content&
注:以上示例涉及到后置代码的,其作用都是用来刷新相关的Label的,所以略掉了。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:291149次
积分:10704
积分:10704
排名:第953名
原创:914篇
评论:19条
(129)(390)(152)(6)(4)(11)(7)(4)(8)(3)(5)(4)(6)(7)(5)(10)(8)(8)(5)(3)(2)(6)(3)(3)(3)(3)(15)(3)(5)(5)(10)(19)(9)(8)(20)(18)(7)二次元同好交流新大陆
扫码下载App
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(3995)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_080',
blogTitle:'ScriptManager控件的功能',
blogAbstract:'ScriptManager控件在先前我们介绍UpdatePanel、Timer等控件时已经使用过,而这个控件的角色相当重要,堪称整个ASP.NET AJAX机制的核心。\r\n他负责几项主要的功能:\r\n1.&& 负责自动建立客户端浏览器上需要的AJAX Client-Script(也就是JavaScript代码)。\r\n2.&& 配合UpdatePanel提供异步Postback的能力,并且“管理”异步Postback的进行。\r\n3.&&',
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:0,
publishTime:0,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:1,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}【ASP.NET】利用UpdatePanel、ScriptManager、Timer完成定时局部更新
【ASP.NET】利用UpdatePanel、ScriptManager、Timer完成定时局部更新
在《【ASP.NET】利用UpdatePanel与ScriptManager完成局部的更新》()介绍过如果直接利用C#完成javascript中Ajax的局部更新。
其实在ASP.NET3.5版本之后,可以完全可以像窗体程序《【C#】Timer、窗体大小和屏幕大小》()中的Timer一样,实现javascript中setInterval的特效。
下面用一个例子来说明这个问题。
在一个页面有两个文本,一个是一秒刷新一次,一个不会被更新,其实这完全可以利用《【JavaScript】一个同步于本地时间的动态时间》()完成的。
当然,如果定时更新中涉及一些后台代码,用ASP.NET这样写,也不失为一种好方法。
具体代码如下,上述页面的前端代码Default.aspx
&%@ Page Language=&C#& AutoEventWireup=&true& CodeBehind=&Default.aspx.cs& Inherits=&Timer._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&&/title&
&form id=&form1& runat=&server&&
&asp:ScriptManager ID=&ScriptManager1& runat=&server& /&
&asp:UpdatePanel ID=&UpdatePanel1& runat=&server& UpdateMode=&Conditional&&
&ContentTemplate&
&asp:Label ID=&Label1& runat=&server& /&
&asp:Timer ID=&Timer1& runat=&server& Interval=&500& OnTick=&Timer1_Tick& /&
&/ContentTemplate&
&/asp:UpdatePanel&
&asp:Label ID=&Label2& runat=&server& /&&br /&
后端代码Default.aspx.cs如下:
using System.Collections.G
using System.L
using System.W
using System.Web.UI;
using System.Web.UI.WebC
namespace Timer
public partial class _Default : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
Label1.Text = DateTime.Now.ToString();
Label2.Text = DateTime.Now.ToString();
protected void Timer1_Tick(object sender, EventArgs e)
Label1.Text = DateTime.Now.ToString();
Label2.Text = DateTime.Now.ToString();
这样话,在Default.aspx标签仅能管辖&asp:UpdatePanel&中&ContentTemplate&标签内的内容,出了这个标签的组件,即使后端代码Default.aspx.cs涉及到这个组件没有报错,由于UpdatePanel的存在,ASP.NET也不会UpdatePanel以外的组件。如上方所示的在UpdatePanel以外的Label2就不会被Timer1所操作。Timer1的Tick事件就算有关于Label2的代码,也仅能操作其中的Label1。
此外,还有一个小提示,Timer1必须被设置Interval,表示Timer1_Tick方法会在多少多少毫秒执行1次,这样Timer才会生效,不会Timer没有Interval是不会更新任何东西的。
我的热门文章
即使是一小步也想与你分享使用ScriptManager动态生成并使用Timer不停刷新Table,每个TableCell里面添加了一个CheckBox控件,CheckBox的Checked提交问题
[问题点数:100分,结帖人lethe]
使用ScriptManager动态生成并使用Timer不停刷新Table,每个TableCell里面添加了一个CheckBox控件,CheckBox的Checked提交问题
[问题点数:100分,结帖人lethe]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
2010年 总版技术专家分年内排行榜第一2009年 总版技术专家分年内排行榜第一
2011年 总版技术专家分年内排行榜第二
本帖子已过去太久远了,不再提供回复功能。我想在我的.net网站上显示日期和时间,在VS2010上我用Timer控件,用lable显示,为什么不能正常运行_百度知道
我想在我的.net网站上显示日期和时间,在VS2010上我用Timer控件,用lable显示,为什么不能正常运行
网站运行结果是:ID 为“Timer1”的控件需要页面上有 ScriptManager。ScriptManager 必须在任何需要它的控件之前出现。求高人指点
提问者采纳
然后用IO可以实现,那样的话其它窗口也会改变,除非你用皮肤控件,文件显示可以用listview。 savafiledialog窗口样式是不能改变的,不会太难自定义一个窗口
其他类似问题
为您推荐:
其他7条回答
你好!!我想你的意思是在自己的页面上显示当地时间(动态到秒),用VS开发的,所以你能看到TImer控件,不过那控件多用在form程序的计时方面,至于在页面上显示时间倒没用过,其实你要实现显示时间可以用脚本语言的,就像下面的一样,把&script&&/script&和其中的代码复制到页面代码就行
&body onload=&setInterval(gettime,1000)&&
&script language=&javascript&&
function gettime()
var now=new Date();
var year=now.getYear();
var month=now.getMonth();
var day=now.getDay();
var hour=now.getHours();
var minute=now.getMinutes();
var second=now.getSeconds();
$(&abc&).innerHTML=&现在是:&+year+&年&+month+&月&+day+&日&+hour+&:&+minute+&:&+
1:托一个timer控件和lable控件,当然还需要无刷新控件;2:修改timer控件的属性Interval为1000,也就相当于每隔一秒刷新一次;3:添加timer控件的ontick事件;4:在timer控件的ontick事件中添加代码: Label1.Text = DateTime.Now.ToString();5:编译运行。
在页面的最上面,from里面,拖一个ScriptManager 进去就可以了什么都不用改,直接放一个ScriptManager空间就可以了,这个是使用AJAX必须要有的控件。对了,你先看看你有没有AJAX组件。谢谢采纳
我按照您的方法把ScriptManager拖到页面上,网页上可以显示时钟,但是时钟每过一秒整个页面就刷新一次,该怎么处理
把timer控件放到updatepanle控件里面就可以了,这个是无刷新控件。
我按照你的方法做了,为什么显示“应用程序中的服务器错误”“ID 为“UpdatePanel1”的控件需要页面上有 ScriptManager。ScriptManager 必须在任何需要它的控件之前出现。”
ScriptManager 必须在所有的Ajax控件之前放置。否则会造成编译错误的
你把工具箱中的ScriptManager控件,放到&form&标签后面就可以了。试试吧~
出什么状况,可以具体点说么 ,可能是timer的那个更新秒数你没有改成一秒的吧
在控件里面找到ScriptManager,拖一个到画面上(就像你拖一个文本框到画面上一样的)即可
我按照您的方法把ScriptManager拖到页面上,网页上可以显示时钟,但是时钟每过一秒整个页面就刷新一次,该怎么处理
试试看用updatepanel,画面上放一个updatepanel,然后把timer放到updatepanel里面去。事实上,如果只是在网站上显示日期和时间,用javascript就可以做到,无需控件的。比如:&script type=&text/javascript&&function show(){var aa=new Date();bb=aa.getYear()+&年&+(aa.getMonth()+1)+&月&+aa.getDate()+&日\r&;bb+=&星期&+'日一二三四五六'.charAt(aa.getDay())+&\r&+aa.getHours()+&时&;bb+=aa.getMinutes()+&分&+aa.getSeconds()+&秒&;document.all.cc.innerHTML=setTimeout(&show()&,1000)}&/script&&body onload=show()&&div id=cc&&/div&
timer控件的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁}

我要回帖

更多关于 没用过的qq卡 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信