如何用微软的ajax里面的timer控件?

jhdxhj 2008-12-09 03:10:57
如何用微软的ajax里面带的timer控件?说说这个控件有哪些属性,以及怎么用,哪个能不能给个例子说说啊
...全文
223 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
超维电脑科技 2009-08-01
  • 打赏
  • 举报
回复
收藏
  • 打赏
  • 举报
回复
你还可以在你的某一个使用了UpdatePanel的aspx上做一个很棒的测试,只要为UpdataPanel中放入一个Timer,在xhtml设计代码上设置这个UpdataPanel中的一个控件的Visible属性为false,然后在这个Timer的Tick事件处理程序中设置这个Timer的Enabled为属性为false(避免循环触发事件),同时设置那个控件的Visible为true。这样,运行时这个控件就是“异步加载”的。

如果你的页面很大、加载很慢,你可以将页面上几个大块内容异步加载,这样原本一个200K的页面可能就变成了只有15K的小页面(其它部分异步加载下来),第一次加载很快。你可以使用一个专门用来测试网站首页加载速度的网站来测试一下你的页面,可以看到超过5倍的速度提高。

当然,异步加载是一种与整个页面平面一次完整显示相比,是不同的用户体验,要兼顾加载速度和用户体验。
lovehongyun 2008-12-09
  • 打赏
  • 举报
回复
http://msdn.microsoft.com/zh-cn/library/bb398865.aspx

http://www.asp.net/AJAX/Documentation/Live/tutorials/IntroToTimerControl.aspx
  • 打赏
  • 举报
回复
我这里有个例子。

首先,把以下ascx文件放入网站(文件名:TestTimerControl.ascx):
<%@ Control Language="C#" %>

<script runat="server">
public int 点击按钮后等待的秒数
{
get
{
EnsureChildControls();
return this.Timer1.Interval / 1000;
}
set
{
EnsureChildControls();
this.Timer1.Interval = value * 1000;
}
}

public string 按钮文字
{
get
{
EnsureChildControls();
return this.Button1.Text;
}
set
{
EnsureChildControls();
this.Button1.Text = value;
}
}

public event EventHandler<EventArgs> 到时间提醒;

protected void Button1_Click(object sender, EventArgs e)
{
this.Timer1.Enabled = true;
}

protected void Timer1_Tick(object sender, EventArgs e)
{
Timer1.Enabled = false;
if (this.到时间提醒 != null)
this.到时间提醒(this, EventArgs.Empty);
}
</script>

<asp:Button ID="Button1" runat="server" Text="定时" OnClick="Button1_Click" />
<asp:Timer ID="Timer1" runat="server" Enabled="False" OnTick="Timer1_Tick" />


这个用户控件上有一个button和一个Timer,同时有两个属性:

1. 点击按钮后等待的秒数。点击按钮之后,演示暂停几秒钟之后才触发事件进行进一步的处理。
2. 按钮文字。用来区分测试时的按钮。

除此以外,还有一个事件 “到时间提醒”。


下面是一个测试这个ascx的页面
<%@ Page Language="C#" %>

<script runat="server">
protected void aa(object sender, EventArgs e)
{
this.Label1.Visible = false;
this.TestTimerControl1.Visible = false;
}

protected void bb(object sender, EventArgs e)
{
this.Label2.Text = DateTime.Now.ToLongTimeString();

}


</script>

<%@ Register Src="TestTimerControl.ascx" TagName="TestTimerControl" TagPrefix="uc1" %>
<!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>
</head>
<body>
<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" Text="Label-1"></asp:Label>
<uc1:TestTimerControl ID="TestTimerControl1" runat="server" 点击按钮后等待的秒数="3" 按钮文字="隐藏"
On到时间提醒="aa" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="Label2" runat="server" Text="Label-2"></asp:Label>
<uc1:TestTimerControl ID="TestTimerControl2" runat="server" 点击按钮后等待的秒数="2" 按钮文字="显示现在的时间"
On到时间提醒="bb" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>


这个页面拖入两个测试ascx,并且分别设置各自的按钮文字和等待时间(3秒、2秒),并且注册第一个ascx实例的事件响应行为为隐藏自己,而第二ascx实例的事件响应行为为更新页面上的一个Label。

运行一下这个aspx,可以看到点击按钮后等待了固定的时间,才触发随后的事件。而不是立刻触发事件。
jiang_jiajia10 2008-12-09
  • 打赏
  • 举报
回复
http://hi.baidu.com/isbx/blog/item/e4839f2f2187103b1e3089eb.html
参考一下

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧