Tutorial: Introduction to AJAX Timer Control in ASP.NET and VB


V4 Ajax Tutorials
Server Intellect Cloud Hosting

Tutorial: Introduction to AJAX Timer Control in ASP.NET and VB

This tutorial was created with Microsoft's ASP.NET AJAX Extensions, which can be downloaded at this link

In this tutorial, we will introduce you to the AJAX Timer Control. This Control can be used to initiate a refresh of an UpdatePanel in a certain timeframe. We are also able to refresh the entire page using the Timer Control. This simple examples illustrates how the Timer Control works and how to implement it.

If you're looking for a really good web host, try Server Intellect - we found the setup procedure and control panel, very easy to adapt to and their IT team is awesome!

First, we start by creating an AJAX-Enabled web site in Visual Studio .NET 2005, with the AJAX Extensions installed.
The AJAX Extensions (from Microsoft) make it a whole lot easier to create AJAX web pages, as Visual Studio will add in the necessary assembly references, etc. into the Web.config

When we first open our Default.aspx page, we should already have a Script Manager:

<asp:ScriptManager ID="ScriptManager1" runat="server" />

Next, we will create a Timer and an UpdatePanel:

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />

<asp:Timer runat="server" id="Timer1" interval="5000" ontick="Timer1_Tick" />
<asp:UpdatePanel runat="server" id="TimePanel" updatemode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger controlid="Timer1" eventname="Tick" />
</Triggers>
<ContentTemplate>
<asp:Label runat="server" id="Label1" />
</ContentTemplate>
</asp:UpdatePanel>
</form>

Note the ontick and interval attributes of the Timer Control. The interval is in milliseconds, so every 5 seconds, the UpdateTimer_Tick method will be called.
Also note the eventname attribute of the Trigger. This tells the page what is going to cause (or trigger) the UpdatePanel to update.

If you're ever in the market for some great Windows web hosting, try Server Intellect. We have been very pleased with their services and most importantly, technical support.

Finally, we add logic to the code-behind. We are simply going to tell it to display the current time in a Label. This way we can see exactly when the UpdatePanel is being refreshed.

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub

Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text = DateTime.Now.ToString()
End Sub
End Class

Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!
 


Comments
Kenneth said:

Hi, I get this 'Sys' is undefined when debugging the website. I have followed everything above. May I know why is this so? Can anyone email me the answer? Help would be greatly appreciated!!! Thanks

Posted Nov 4, 2008 1:43 AM
Kenneth said:

Sry!!! Can anyone pls post the answer here. Thanks

Posted Nov 4, 2008 1:45 AM
Hussam said:

Thank you for this valuable website

Posted Nov 12, 2008 2:53 AM
Kumar said:

Excellent Code thanks

http://www.planetsourcecode.in

Posted May 5, 2009 1:15 PM
Renju said:

you are not having the ajax .net component installed in ur machine

Posted Feb 9, 2010 7:05 AM
tissot mens watches? said:

I am in support of wonderland, this project is seeing very good fame and should be continued.

Posted Jul 5, 2011 3:15 AM
pandora bracelets and charms said:

Way to stay positive and stick with something you love!

Posted Jul 5, 2011 3:15 AM
Hermes said:

The i cars also signal

Posted Jul 31, 2011 8:51 PM
www.outlet-louisvuitton.co.uk said:

www.outlet-louisvuitton.co.uk

Posted Aug 6, 2011 3:29 AM
Antakya Biberi said:

antakya biberi zayiflama hapi antakya biber hapi

Posted Oct 23, 2011 7:39 AM
Antakya Biberi said:

antakya biberi zayiflama hapi antakya biber hapi

Posted Oct 23, 2011 7:39 AM
zayıflama hapı said:

maurers zayıflama hapı termojenik zayıflama hapları zayıflama ile zayıflama bölgesel zayıflama

Posted Oct 23, 2011 7:46 AM
Ken Griffey Jr Shoes said:

Manufactured with some of the finest materials in the industry,Ken Griffey Jr Shoes you will be pleased that your purchase Ken Griffeys will not only last, but that your body will have the ergonomic support it deserves. http://www.kengriffeys2011.com

Posted Oct 26, 2011 4:25 AM
Y3 Trainers UK said:

Adidas Y3 Trainers became a part of the Adidas group, and today they have become a recognised brand partnership around the world. But at the time Y3 trainers were largely being developed as a men's fashion item. Y3 Trainers UK offering both style and performance.

Posted Oct 26, 2011 4:27 AM
Nike Heels said:

Most ladies like high heels shoes www.nikeheelsshopping.com Nike Heels For Women

Adidas Y3 Trainers became a part of the Adidas group, and today they have become a recognised brand partnership around the world. But at the time http://www.y3-trainers.com Y3 trainers http://www.kengriffeys2011.com Ken Griffey Jr Shoes

Posted Nov 29, 2011 10:04 PM
Lebron 8 said:

Nike Dunk Heels took inspiration from those well known http://www.shoeslisting.com Nike Dunks with cartoon character, this one features the character likes Detective Conan. TheNike Heels Black Orange features with the pattern at the collar with his eyeglasses, and the black smooth leather for ankle strap and toe mudguard.

Posted Nov 29, 2011 10:04 PM

Leave a Comment