Web Timer Control
Timer Control is purely a web-based timer control.
Timer Class
Provides a mechanism for executing a method at specified intervals.
Timer Control's stopwatch counts downwards from 'X' to ZERO time for measuring elapsed time.
Events
OnIntervalReached
Notifies your application when a specified period of time has elapsed. It is trigged through a client callback method.
So you can't update the page contents.
protected void Timer1_IntervalReached(object sender, CodeControls.TimerEventArgs e)
{
}
OnTimeOutOccurred
Notifies your application when a specified Time Out has been reached.
protected void Timer1_TimeOutOccurred(object sender, CodeControls.TimerEventArgs e)
{
}
Implementation
Timer Control is built on Client CallBack technique. So no postback is required for notifying your application when inteval or timeout reached.
Since the mechanism implements client callback method, you are limited to the following:
You can perform database operations.
You can't redirect the current page
You can't modify the content of the current page.
You can have access to the cookies and catch.
You can't store the value in the session.Because session values are made visible after the postback.
To overcome this limitation, this control provides a mechanism to do a full postback on Time Out.
So you can modify,redirect the current page if DoPostBackOnTimeOut attribute set to TRUE.
Properties & Definition
IsAutoStart
If set to true,Timer Countdown starts immediately after page load.
If set it to false,Timer Countdown won't triggered at the page load. You should call Timer1.ManualStart() method in your page to trigger the Timer.
Enabled
If it is set to false, it won't register related script to the page.
To run Timer,This property needs to be set true.
ServerSideTimeSynchronize
The Timer control runs based on a javascript. We can't claim that Timer control always mantains perfect timings. It might miss a couple of seconds.
If ServerSideTimeSynchronize set to true, the time calculation are based on the server. After each interval, The timer gets the amount of Time Left from the server and updates the stop watch.
This is will lead to slight bumps in the countdown.
DoPostBackOnTimeOut
Timer StopWatch is a java script based program. When the interval reached, it enables the client callback functions.
So no post back is required for notifying your application when interval or timeout reached. As a result of this ClientCallBack ,you can't modify the page contents.
This property allows control to trigger a TimeOut Event with full post back. Now, you can modify the contents or redirect to a another page.
This won't create postback for the IntervalReached Event.
DisableRightClick
It disables the mouse right click .
Mouse right click affects the timer stopwatch. So it is recommended to set DisableRightClick to true.
If you don't want to disable the mouse right click, then set ServerSideTimeSynchronize to true.
So that it updates the Timer StopWatch for every interval.
Interval
Interval is defined in seconds.
Raises a IntervalReached event on your application when a specified period of time has elapsed.
TimeOut
TimeOut is defined in seconds.
Raises a TimeOut event on your application when a TimeOut has elapsed.
It is raised only once for entire Timer period.
***Timer is set to last interval time, when a postback occurs.
Creating a New Timer Control
Add the following to your .aspx page.
<%@ Register Namespace="CodeControls" TagPrefix="cc" %>
<cc:Timer ID="Timer1" runat="server" DoPostBackOnTimeOut="false" Font-Names="Verdana" Font-Size="68px" ForeColor="#FF8000" Interval="5" ServerSideTimeSynchronize="True" TimeOut="9" OnIntervalReached="Timer1_IntervalReached" OnTimeOutOccurred="Timer1_TimeOutOccurred" IsAutoStart="true" DisableRightClick="true"></cc:Timer>
Using a Timer Control
Suppose you want to update the date time on the server for every 10 seconds.
You could create a Timer to periodically update date time on the SQL server.
Specifying Time on a Timer Control
See Interval and Timeout properties. Both are defined in seconds.
Specifying Themes on a Timer Control
Timer Control inherits Label properties. So you can use it like ASP.NET Label.
Specifying Stop Watch Visibility on a Timer Control
If you don�t want to display the stopwatch/countdown, you can set visible to false. But Timer controls runs regardless of visible property. Only Enable property disables the Timer control.
评论0