title: AJAX - ASP.NET - Timer delay problem
body: <p>I'm trying to make an webapplication where you see an Ajax countdown timer. Whenever I push a button the countdown should go back to 30 and keep counting down.</p>
  
  <p>Now the problem is whenever I push the button the timer keeps counting down for a second or 2 and most of the time after that the timer keeps standing on 30 for to long.</p>
  
  <p>WebForm code:
      
      
      
      </p>
  
  <pre><code>&lt;asp:UpdatePanel ID="UpdatePanel1" runat="server"&gt;
      &lt;ContentTemplate&gt;
          &lt;asp:Label ID="Label1" runat="server" Text="geen verbinding"&gt;&lt;/asp:Label&gt;
          &lt;br /&gt;
          &lt;asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /&gt;
          &lt;br /&gt;
      &lt;/ContentTemplate&gt;
      &lt;Triggers&gt;
          &lt;asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" /&gt;
      &lt;/Triggers&gt;
  &lt;/asp:UpdatePanel&gt;
  &lt;asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick"&gt;
  &lt;/asp:Timer&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p></p>
  
  <p>Code Behind:</p>
  
  <pre><code>static int timer = 30;
  protected void Page_Load(object sender, EventArgs e)
  {
      Label1.Text = timer.ToString();
  }
  protected void Timer1_Tick(object sender, EventArgs e)
  {
      timer--;
  
  }
  protected void Button1_Click(object sender, EventArgs e)
  {
      timer = 30;         
  }
  </code></pre>
  
  <p>Hope somebody knows what the problem is and if there is anyway to fix this.</p>
  
  <p>Thanks in advance!</p>