ARTICLE

Timer control in ajax

Posted by Walter Scott Articles | Visual Basic 2010 September 12, 2011
With the help of this control we can be easily find out time for any ajax application in asp.net
 
Reader Level:

Introduction: Use timer control in ajax.

Step:1
Open visual studio and go to file menu.

  • Select website option .
  • Now we select asp.net website.
  • Default.aspx page open.
asp.gif

default.gif

Step:2 Go to solution explorer and right click.

  • Select a add new item option.
  • Now  we select a web forms and click in add.
add-page.gif

web-forms.gif

Step:3 Now we add ajax control.

  • Go to toolbox and click ajax extensions and select timer.updatepanel,scriptmanager ,updateprogress control.
  • Now we go to source and write a code.
control-page.gif

Code:4 

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="sachin.aspx.vb" Inherits="sachin" %>

<!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> Timer control in ajax</title>
</head>
<
body>
     
<form id="form1" runat="server">
<
div>
     <
asp:ScriptManager ID="ScriptManager1" runat="server">
       </
asp:ScriptManager>
    </
div>
       <
asp:UpdatePanel ID="UpdatePanel1" runat="server">
<
Triggers>
       <
asp:AsyncPostBackTrigger ID ="Timer1" EventName="Tick">
        </
asp:AsyncPostBackTrigger>
</
Triggers>
     <
ContentTemplate>
<table border = "1">
        
 <tr>
<
td><asp:Label ID = "Label1" runat = "server" Text = "java"></asp:Label></td>
   <
td align = right><asp:Label ID = "lblc" runat = "server" Text = "100"></asp:Label></td>
<
tr
    <td><asp:Label ID = "Label2" runat = "server" Text = ".NET"></asp:Label></td>
<td align =right><asp:Label ID = "lbld" runat = "server" Text = "123"></asp:Label></td>
  <
tr>
    <
td><asp:Label ID ="Lable3" runat = "server" Text = "php"></asp:Label></td>
                <
td align =right><asp:Label ID = "lble" runat = "server" Text = "124"></asp:Label></td>
</
tr>
</
tr>
</
tr>
</
table>
</ContentTemplate>
</
asp:UpdatePanel>
               <
asp:UpdateProgress ID="UpdateProgress1" runat="server">
                <
ProgressTemplate>updating....</ProgressTemplate>
</asp:UpdateProgress>
         
<asp:Timer ID="Timer1" runat="server" Interval = "20" OnTick = "Timer1_Tick">
  </
asp:Timer>
</
form
>
</body>
</
html>

Step:4 Now double click in timercontrol and write a code.

Code:
     Protected Sub Timer1_Tick(sender As Object, e As System.EventArgs) Handles Timer1.Tick
            Threading.Thread.Sleep(500)
            lblc.Text = ((Int32.Parse(lblc.Text)) + 1).ToString()
            lbld.Text = ((Int32.Parse(lbld.Text)) + 1).ToString()
            lble.Text = ((Int32.Parse(lble.Text)) + 1).ToString()
     End
Sub

out-put.gif

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
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.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Team Foundation Server Hosting
Become a Sponsor