Net-informations.com
SiteMap  | About    

ASP.NET Ajax Timer

The Timer control can work as a trigger to an area of the page that is wrapped with an UpdatePanel Control. It performs postbacks at defined intervals. The Interval property is defined in milliseconds, so that setting the Interval property to 5000 milliseconds will refresh the UpdatePanel control every 5 seconds.

The following asp.net program placed a Timer and label controls inside the UpdatePanel control area and one label control outside the UpdatePanel control area. When you run this program first label shows the current server time as page loaded time. After five seconds the second Label inside the UpdatePanel control shows the current server time. After that each five seconds you can see the second label only updating the current server time , because partal page updating is happening at defined intervals.

Default.aspx

  

<!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>Untitled Page</title>
</head>
<body>
	<form id="form1" runat="server">
	<div>
		<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
		<br /><br />
		<asp:ScriptManager ID="ScriptManager1" runat="server"/>
		<asp:Timer ID="Timer1" runat="server" interval="5000" ontick="Timer1_Tick" />
		<asp:UpdatePanel ID="UpdatePanel1" runat="server">
			<ContentTemplate>
				<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
			</ContentTemplate>
			<Triggers>
				<asp:AsyncPostBackTrigger controlid="Timer1" eventname="Tick" />
			</Triggers>
		</asp:UpdatePanel>
	</div>
	</form>
</body>
</html>


Click the following links to see full source code

C# Source Code
VB.NET Source Code
Default.aspx.cs
Default.aspx.vb





net-informations.com (C) 2016    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.