AdBlock Detected

We provide high-quality source code for free. Please consider disabling your AdBlocker to support our work.

Buy me a Coffee

Saved Tutorials

No saved posts yet.

Press Enter to see all results

How to use Timer ajax control c#.net Asp.net:Trickcode

By pushpam abhishek
Listen to this article

Countdown -Timer ajax control c#.net Asp.net

Hi, Today we will learn about Timer ajax control In Asp.net. we can find the timer control in ajax controls list from Toolbox in asp.net.

Here we take an example of ajax timer controls in asp.net. we will display current time and date on web forms in asp.net.

Timer ajax control In Asp.net

  • Note: need ajax control toolkit to feature first.
  • You can download it from http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/
  • here are many samples for ajax tools & after downloading this sample kit,
  • you can find many sample code for a way to use ajax controls in your website
  • In Addition, I make CSS for the round corner of div tag, my div is as a circle
////////////////
//Design Page … Save it as timer.aspx
//////////////////

<%@ Page Language=”C#”AutoEventWireup=”true”CodeFile=”timer.aspx.cs”Inherits=”timer”%>
<%@ Register assembly=”AjaxControlToolkit”namespace=”AjaxControlToolkit”tagprefix=”asp”%>
<!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>Untitled Page</title>
    <style type=”text/css”>
        .circle
        {
         text-align:center;
        float:left;
        width:60px;
        height:60px;
        background-color:#ffffff;
        border1px solid #000000;
        padding:20px 20px 20px 20px;
        -moz-border-radius50px;
        -webkit-border-radius50px;
        border-radius50px;
     
         font-family:Cambria;
         font-size:35px;
        }
        .styletable
        {
          font-family:Cambria;
            font-size:15px;
         font-weight:bold;
        }
     </style>
</head>
<body>
    <form id=”countdowntimerform” runat=”server”>
    <div><br />
        <asp:ToolkitScriptManager ID=”ToolkitScriptManager1″ runat=”server”>
        </asp:ToolkitScriptManager>
        <br />
        <asp:UpdatePanel ID=”UpdatePanel1″ runat=”server”>
        <ContentTemplate>
         <asp:Timer ID=”Timer1″ runat=”server” Interval=”1000″ ontick=”Timer1_Tick”>
        </asp:Timer>
        <br />
        <br />
        <table width=”260″>
        <tr>
         <td><div class=”circle”><asp:Label ID=”Label1″ runat=”server”></asp:Label></div></td>
         <td><div class=”circle”><asp:Label ID=”Label1″ runat=”server”></asp:Label></div></td>
         <td><div class=”circle”><asp:Label ID=”Label3″ runat=”server”></asp:Label></div></td>
         <td><div class=”circle”><asp:Label ID=”Label4″ runat=”server”></asp:Label></div></td>
        </tr>
        <tr align=”center”><td><b>DAYS</b></td><td><b>HOURS</b></td><td><b>MIN</b></td><td><b>SEC</b></td></tr></table
        </ContentTemplate>
        </asp:UpdatePanel>
         </div>
    </form>
</body>
</html>
/////////////////////////////////////////////////////////////////////////////////////
Code Behind File Save it as timer.aspx.cs
///////////////////////////////////////////////////////////////////////////////

using System;
usingSystem.Collections;
usingSystem.Configuration;
usingSystem.Data;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.HtmlControls;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Xml.Linq;
public partial class timer : System.Web.UI.Page
{
    static DateTime setdt;
    protected void Page_Load(objectsender, EventArgs e)
    {
     
    }
    protected void Timer1_Tick(objectsender, EventArgs e)
    {
         DateTimedt = DateTime.Now;
         TimeSpandiffer;
         System.DateTimedate1 = new System.DateTime(2013, 4, 1, 20, 10, 0);
         differ = date1.Subtract(dt);
         double  t = differ.TotalSeconds;
       
           if(t>0)
           {
               doubleyr, mnth, dy, h, m, s;
               dy = differ.Days;
               h = differ.Hours;
               m = differ.Minutes;
               s = differ.Seconds;
               Label1.Text = dy.ToString();// +” Days ” + h + ” Hours ” + m + ” Minutes ” + s + ” Seconds left for celebration”;
               Label2.Text = h.ToString();
               Label3.Text = m.ToString();
               Label4.Text = s.ToString();
           }
           else
           {
               Timer1.Enabled = false;
           }
    }
}
Do you know:-
If you like the tutorial, then please share this tutorial with your friends on social media.

Share this post

pushpam abhishek

About pushpam abhishek

Pushpam Abhishek is a Software & web developer and designer who specializes in back-end as well as front-end development. If you'd like to connect with him, follow him on Twitter as @pushpambhshk

Comments