TWO TIMERS IN ONE PAGE

Simons Hood

Total Post:70

Points:494
Posted by  Simons Hood
 1122  View(s)
Ratings:
Rate this:

I have two timers in one page but second timer is not working.

<asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick">

</asp:Timer>

<asp:Timer ID="Timer2" runat="server" Interval="5000" OnTick="Timer2_Tick">

</asp:Timer>

Code behind:

protected void Timer1_Tick(object sender, EventArgs e)

{

    lblcurrenttime5.Text = DateTime.Now.ToLongTimeString();

}      

protected void Timer2_Tick(object sender, EventArgs e)

{

    label6.Text = "Timer 2 is working";

  1. Pravesh Singh

    Post:412

    Points:2888
    Re: Two timers in one page

    Hi Samuel,


    Try putting the code you want in the pageLoad method

     protected void Page_Load(object sender, EventArgs e)

        {

          lblcurrenttime5.Text = DateTime.Now.ToLongTimeString();

          label6.Text = "Timer 2 is working";

        }

    Since the page refreshes with the timer, it will pass through the pageload method.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!