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


V4 Ajax Tutorials
Server Intellect Cloud Hosting

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

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.

Yes, it is possible to find a good web host. Sometimes it takes a while. After trying several, we went with Server Intellect and have been very happy. They are the most professional, customer service friendly and technically knowledgeable host we've found so far.

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.

We migrated our web sites to Server Intellect over one weekend and the setup was so smooth that we were up and running right away. They assisted us with everything we needed to do for all of our applications. With Server Intellect's help, we were able to avoid any headaches!

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.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Timer1_Tick(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();
}
}

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
kumar said:

I think the AJAX support should be more flexible, as I suffered more pain while working with asp.net Ajax 2.0

thanks

http://www.planetsourcecode.in A Place For All SoftwareDevelopers

Posted May 5, 2009 1:19 PM
generic cialas said:

Sounds good, curious to check it out.

Posted Jan 31, 2011 2:36 PM
Mani said:

It's very nice article and helpful to learn. Thanks!

Posted May 23, 2011 9:00 AM
viagra pour homme said:

I found it to be very useful. Good tutorial

Posted Jun 24, 2011 10:12 AM
tissot watch prices said:

I imply, I dont need to sound like a know-it-all or anything, however could you could have presumably put a little bit extra effort into this subject.

Posted Jul 5, 2011 2:58 AM
pandora charms on sale said:

I have to say, I dont know if its the clashing colours or the dangerous grammar, however this weblog is hideous!

Posted Jul 5, 2011 2:58 AM
ed meds sale said:

Thanks for making such a killer blog. I arrive on here all the time and am floored with the fresh tutorials here.

Posted Jul 7, 2011 4:28 AM
Louis Vuitton said:

Drive to Stem Shingles Meets Few Expectations

Posted Jul 12, 2011 10:38 PM
premature ejaculation medicine said:

I recently came across your blog and have been reading along. Thank you for tutorials

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

The i cars also signal

Posted Jul 31, 2011 8:57 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
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:47 AM
cialis livraison express said:

I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon.

Posted Dec 20, 2011 3:24 AM

Leave a Comment