Timer control in Asp.net

Sathya4260
Posted by Sathya4260 under ASP.NET AJAX category on | Points: 40 | Views : 3631
Hi,

Sometimes we might need to refresh an particular content of the web page to be refreshed at an certain interval of time, This scenario can be done by using Timer control provided by the Microsoft Ajax controls.

Features:
The Timer control is a server control
This control embeds a JavaScript component into the Web page
performs postbacks at defined intervals
Do partial-page updates at a defined interval
Can post the whole web page also

Things need to be provided:
An instance of the ScriptManager class must be included in the Web page when you use the Timer control.
Interval timing should be mentioned (Milliseconds)
Method which runs when the "OnTick" event occurs

Example:

<asp:ScriptManager runat="server" id="ScriptManager1" />
<asp:UpdatePanel runat="server" id="UpdatePanel1"
UpdateMode="Conditional">
<contenttemplate>
<asp:Timer id="Timer1" runat="server"
Interval="20000"
OnTick="Timer1_Tick">
</asp:Timer>
</contenttemplate>
</asp:UpdatePanel>


Timer control can be used as an Triggers for the updatePanel also.


Example:
<asp:ScriptManager runat="server" id="ScriptManager1" />
<asp:Timer ID="Timer1" runat="server" Interval="20000"
OnTick="Timer1_Tick">
</asp:Timer>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1"
EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Label ID="Label1" runat="server" ></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>

Comments or Responses

Posted by: Ksuresh on: 9/3/2011 Level:Starter | Status: [Member] | Points: 10
Thanks

Regards
suresh

Login to post response