惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Cisco Talos Blog
Cisco Talos Blog
P
Privacy & Cybersecurity Law Blog
I
Intezer
Y
Y Combinator Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
N
Netflix TechBlog - Medium
The Hacker News
The Hacker News
AWS News Blog
AWS News Blog
aimingoo的专栏
aimingoo的专栏
A
About on SuperTechFans
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Stack Overflow Blog
Stack Overflow Blog
Hacker News: Ask HN
Hacker News: Ask HN
酷 壳 – CoolShell
酷 壳 – CoolShell
量子位
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
B
Blog
T
Tor Project blog
C
Cybersecurity and Infrastructure Security Agency CISA
云风的 BLOG
云风的 BLOG
博客园_首页
V2EX - 技术
V2EX - 技术
T
Threat Research - Cisco Blogs
腾讯CDC
宝玉的分享
宝玉的分享
博客园 - 叶小钗
罗磊的独立博客
S
Securelist
The Last Watchdog
The Last Watchdog
Google Online Security Blog
Google Online Security Blog
Scott Helme
Scott Helme
博客园 - 司徒正美
W
WeLiveSecurity
有赞技术团队
有赞技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
Secure Thoughts
NISL@THU
NISL@THU
N
News and Events Feed by Topic
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
雷峰网
雷峰网
大猫的无限游戏
大猫的无限游戏
K
Kaspersky official blog
IT之家
IT之家

博客园 - .............

验证码生成器 十年编程无师自通 模仿桌面外观 Web服务是否失去前进目标 “开源”SOA正在改写IT规划方程式 C#实现的18位身份证格式验证算法 - ............. - 博客园 怎样使用Junit Framework进行单元测试的编写 从一个项目谈XP在国内的应用 - ............. - 博客园 AOP是什么? 在C#中使用Conditional元数据attribute来实现Debug代码 - ............. - 博客园 IBM CRM 系统解决方案 HR软件之我见-小议目前HR供应商 Atlas学习手记(11):使用ModalPopup Extender Atlas学习手记(10):使用AlwaysVisibleControl Extender Atlas学习手记(9):异步调用Page Method Atlas学习手记(8):调用本地Web Service简单介绍 Atlas学习手记(7):使用DragOverlayExtender实现拖放功能 Atlas学习手记(6):使用Atlas UpdateProgress控件 Atlas学习手记(4):使用AutoComplete Extender实现自动完成功能 Atlas学习手记(3):由UpdatePanel开始
Atlas学习手记(5):使用服务端定时控件TimerControl
............. · 2006-08-03 · via 博客园 - .............

转自 TerryLee技术空间
摘要:TimerControl是一个用于服务器端定时器的控件,可用来实时显示数据等,在很多地方都有应用,本文将简单介绍一下TimerControl的使用。

主要内容

1TimerControl介绍

2.完整示例

一.TimerControl介绍

TimerControl是一个用于服务器端定时器的控件,可用来实时显示数据等,在很多地方都有应用,本文将简单介绍一下TimerControl的使用。一个简单的TimerControl如下:

<atlas:TimerControl runat="server" Interval="3000" ID="tickerTimer" OnTick="tickerTimer_Tick" />

它的属性解释如下:

属性

解释

Interval

时间间隔,隔多长时间刷新一次,单位为ms

Interval="3000"

OnTick

每隔Interval时间后向服务器端触发事件,是一个服务器端的方法

OnTick="tickerTimer_Tick"

Enabled

设置TimerControl控件是否可用,通过此属性我们可以自行控制开启和停止定时。

二.完整示例

下面我们通过一个简单的示例来演示TimerControl的使用。在很多网站上我们都可以看到一些股票代码等信息,这些数据都是实时刷新的,这里我们模仿一个股票代码示例。

1.添加ScriptManager,这个不用多说,只要是Atlas应用都必须添加的。设置它的EnablePartialRendering属性为true,这里要用UpdatePanel来做局部刷新。

<atlas:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server" />

2.添加TimerControl控件

<atlas:TimerControl runat="server" Interval="3000" ID="tickerTimer" OnTick="tickerTimer_Tick" />

代码很简单,指定间隔的时间为3s,触发的事件为tickerTimer_Tick

3.添加UpdatePanel,用两个Label来分别显示公司的名称和虚拟股票代码:

<atlas:UpdatePanel runat="server" ID="UpdatePanel1">

    
<Triggers>

        
<atlas:ControlEventTrigger ControlID="tickerTimer" EventName="Tick" />

    
</Triggers>

    
<ContentTemplate>

      
<h2>Atlas TimerControl Example</h2>

      
<asp:Label ID="CompanyName" runat="server" Font-Bold="True" Font-Size="Larger">Tokyo Traders:</asp:Label>

      
<asp:Label ID="CompanyValue" runat="server" Font-Bold="True" Font-Size="Larger" ForeColor="Red">20</asp:Label>

    
</ContentTemplate>

</atlas:UpdatePanel>

4.编写一个简单的Web Service,用来返回股票代码,这里我们用产生一个随机数来模拟:

using System;

using System.Web;

using System.Collections;

using System.Web.Services;

using System.Web.Services.Protocols;
 

/// <summary>

/// Summary description for TimerWebService

/// </summary>


[WebService(Namespace 
= "http://tempuri.org/")]

[WebServiceBinding(ConformsTo 
= WsiProfiles.BasicProfile1_1)]

public class TimerWebService : System.Web.Services.WebService {

    
public TimerWebService () {

        
//Uncomment the following line if using designed components 

        
//InitializeComponent(); 

    }


    [WebMethod]

    
public string GetCode()

    
{
        Random r1 
= new Random();

        
return r1.Next(20,200).ToString();

    }

}

5.编写TimerControl的触发事件tickerTimer_Tick,代码很简单,只要把返回的数据显示在Label上就可以了。

protected void tickerTimer_Tick(object sender, EventArgs e)

{
    TimerWebService service 
= new TimerWebService();

    
this.CompanyValue.Text = service.GetCode();

}

至此一个简单的TimerControl示例就完成了,看一下运行效果,起始的时候:


3s
之后:

完整示例下载:http://terrylee.cnblogs.com/Files/Terrylee/TimerControlDemo.rar