ARTICLE

How to use AJAX Timer control in ASP.NET using VB.NET

Posted by Shalini Juneja Articles | ASP.NET using VB.NET May 06, 2011
In this article you will learn that how to use AJAX Timer control to update a region of a page.
Download Files:
 
Reader Level:

Introduction

The Timer control is pretty simple to use at a specified interval, The control fires its tick event. Inside an Event handler for this Event you can execute any code see fit if you hook up the Timer to the UpdatePanel using its Triggers Collection, you can update a single region of a page whenever the Timer control Ticks-that is when it fires its Tick Event. Here we are Discussing an example using the Timer control in an aspx page to update the region of a page. The Timer will tick every one second and update a Lable. The implementation of example needs a ScriptManager, Timer and a Label control.

 
Getting Started

  • Simply create a new ASP.NET web application.
  • Drag a ScriptManager, Timer and a Label control on your web page. The page will look like Below.

    ajaxtimer1.gif
     
  • You can also add control by the below code.

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
    <!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 id="Head1" runat="server">
        <title>How to Use AJAX Timer</title>
    </
    head>
    <
    body>
        <form id="form1" runat="server">
        <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
        </div>
          <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <br />
                  <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="XX-Large"
                       
    ForeColor="#0033CC"></asp:Label>
                </ContentTemplate>
                <Triggers>
                  <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
                </Triggers>
           </asp:UpdatePanel>
              <br />
              <asp:Timer ID="Timer1" runat="server" Interval="60" ontick="Timer1_Tick"></asp:Timer>
        </form>
    </
    body>
    </
    html>
     
  • Then attach the below code in code behind file.

       
    Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            UpdateLabel()
       
    End Sub
        Private Sub UpdateLabel()
            Label1.Text =
    DateTime.Now.ToString()
       
    End Sub
     
  • Now run your application.

Output:-

ajaxtimer2..gif


Summary

In this article you Learned that how to use AJAX Timer control.

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Team Foundation Server Hosting
Become a Sponsor