1

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";
}       
Ondrej Janacek
  • 12,486
  • 14
  • 59
  • 93

1 Answers1

0

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.

Aelgawad
  • 184
  • 1
  • 16
  • Make sure that the elements being updated (Labels along with the timers) are inside the tag which is inside tag right under the tag. – Aelgawad Dec 15 '13 at 22:58