timer in asp.net

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • free2cric@yahoo.com

    timer in asp.net

    Hi, I intend to use timer whose purpose is to show the current time by
    a label on form after specified interval. But it not working . why?
    thanks
    cric

    using System;
    using System.Collecti ons;
    using System.Componen tModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Timers;
    using System.Web.Sess ionState;
    using System.Web.UI;
    using System.Web.UI.W ebControls;
    using System.Web.UI.H tmlControls;

    namespace WebApplication1
    {
    /// <summary>
    /// Summary description for imageshow.
    /// </summary>
    public class imageshow : System.Web.UI.P age
    {
    protected System.Web.UI.W ebControls.Labe l Label1;
    protected System.Web.UI.W ebControls.Butt on Button1;
    protected System.Timers.T imer m_heartbeatTime r = new
    System.Timers.T imer();

    private void Page_Load(objec t sender, System.EventArg s e)
    {

    // Put user code to initialize the page here
    }


    public void CheckForTimer1E vent(object sender,
    System.Timers.E lapsedEventArgs e)
    {
    m_heartbeatTime r.Stop();
    Label1.Text = "now time is " + DateTime.Now;
    m_heartbeatTime r.Start();
    }
    #region Web Form Designer generated code
    override protected void OnInit(EventArg s e)
    {
    //
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    //
    InitializeCompo nent();
    base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeCompo nent()
    {
    this.Button1.Cl ick += new System.EventHan dler(this.Butto n1_Click);
    this.Load += new System.EventHan dler(this.Page_ Load);

    }
    #endregion

    private void Button1_Click(o bject sender, System.EventArg s e)
    {
    System.Int32 m_heartbeatTime rInterval = 500;

    m_heartbeatTime r.Interval = m_heartbeatTime rInterval;
    m_heartbeatTime r.Enabled = true;
    m_heartbeatTime r.Start();

    m_heartbeatTime r.Elapsed += new
    System.Timers.E lapsedEventHand ler(CheckForTim er1Event);
    }
    }
    }

  • Mythran

    #2
    Re: timer in asp.net


    <free2cric@yaho o.com> wrote in message
    news:1117176909 .587486.22050@z 14g2000cwz.goog legroups.com...[color=blue]
    > Hi, I intend to use timer whose purpose is to show the current time by
    > a label on form after specified interval. But it not working . why?
    > thanks
    > cric[/color]


    Because, the timer is raising an event on the server side. The way ASP.Net
    works is the client requests a page from the server, the server receives the
    request, parses the server-side content, executes the code-behind and
    server-side code, then returns the results (usually in the form of a web
    page [html]) back to the client machine.

    The page and execution of the code is complete, probably before the timer
    elapses the first time.

    HTH, maybe someone else can explain it better than I.

    Mythran

    Comment

    Working...