<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHeader" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderForTitleAndIntro" Runat="Server">
<div class="ArticleTitle"><h1>Timer Control</h1></div>
<div class="ArticleContents">Timer control performs postbacks at the defined intervals. This is generally used to update the content of UpdatePanel at a defined interval. Apart from this it can be used to post the whole page at defined interval. </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PlaceHolderForContents" Runat="Server">
<br />
There are few properties that are used more frequetly, these are <br /><br />
<table width="100%" class="TutoPropPlaceHolder" border="1" cellpadding="2" cellspacing="1">
<tr>
<td class="DemoCP">Interval</td>
<td>
Gets or sets the time interval in milliseconds after OnTick event of Timer control will fire.
</td>
</tr>
<tr>
<td class="DemoCP">OnTick</td>
<td>
Used to specifiy the method name that will after specified time interval.
</td>
</tr>
</table>
<br /><br />
<div class="ArticleContents">
Timer control can be used in two ways.<br /><br />
<!-- START - Demo Section -->
<table class="DemoPlaceHolder" border="1" cellpadding="2" cellspacing="4">
<tr>
<td class="DemoTitle">
DEMO : Timer Control
</td>
<td align="right">
<a class="DemoShowSource" href="../../misc/codeviewer/default.aspx?pagename=~/tutorials/ajax/timer.aspx" target="_blank">Show Source Code</a>
</td>
</tr>
<tr>
<td>
<b>1. Inside an UpdatePanel control</b><br />
When the timer control is used inside an <a href="UpdatePanel.aspx">UpdatePanel</a> control, the Timer control automatically works as a trigger for <br />the UpdatePanel control, however we can override this behavior by setting the ChildrenAsTriggers property of UpdatePanel as false.
<br /><br />In this case lets say server takes 7 seconds to process the request then following message <br />will change after every 12 (5+7) seconds as I have specified Timer interval property as 5000 milliseconds (5 seconds).
<br /><br />
Following message will change after every 5 seconds<br />
<asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
<ContentTemplate>
<br />
<asp:Label runat="Server" ID="lblMessage1" Text="Please wait Timer Control from inside UpdatePanel will fire in 5 seconds" ForeColor="Green" />
<asp:Timer runat="Server" ID="Timer1" OnTick="Timer1_Tick" Interval="5000" />
</ContentTemplate>
</asp:UpdatePanel>
<pre><asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label runat="Server" ID="lblMessage1" Text="Please wait ..." SkinID="FormValueMessage" />
// Timer control inside UpdatePanel
<asp:Timer runat="Server" ID="Timer1" OnTick="Timer1_Tick" Interval="5000" />
</ContentTemplate>
</asp:UpdatePanel></pre>
</td>
<td><a href="../../userfiles/samples/dotnetfundaaspajax.zip">Download Sample project with Source Code</a></td>
</tr>
<tr>
<td><b>2. Timer Control Outside UpdatePanel</b><br />
When the Timer control is outside an UpdatePanel control, we must explicitely define the Timer control as trigger <br />for the UpdatePanel control to be updated.
<br /><br />In this case Timer, Timer OnTick event will fire after every 3 seconds irrespective of<br /> how many seconds server takes to process the request as I have specified Interval as 3000 milliseconds.
<br /><br />
Following message will change after every 3 seconds<br />
<asp:UpdatePanel runat="server" ID="UpdatePanel2" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer2" EventName="Tick" />
</Triggers>
<ContentTemplate>
<br />
<asp:Label runat="Server" ID="lblMessage2" Text="Please wait Timer Control from outside UpdatePanel will fire in 3 seconds" ForeColor="Blue" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:Timer runat="Server" ID="Timer2" OnTick="Timer2_Tick" Interval="3000" />
<pre><asp:UpdatePanel runat="server" ID="UpdatePanel2" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer2" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Label runat="Server" ID="lblMessage2" SkinID="FormValueMessage" />
</ContentTemplate>
</asp:UpdatePanel>
// Timer control outside UpdatePanel
<asp:Timer runat="Server" ID="Timer2" OnTick="Timer2_Tick" Interval="3000" /></pre>
</td>
<td><a href="../../userfiles/samples/dotnetfundaaspajax.zip">Download Sample project with Source Code</a></td>
</tr>
</table>
</div>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="PlaceHolderFooter" Runat="Server">
</asp:Content>
Go Top