Asp.net Timer and Update Panel

Hi, I searched a lot for stack overflows to find a suitable answer to my question, but could not find it. Hope you guys help me with my problem.

I have a web application that has two update panels.

The 1st update panel contains only a timer, the interval of which is only one second, and it acts as a countdown timer.

The second update panel is a conditional panel, which is updated only after the countdown has finished.

The problem I am facing is that when I publish my web application, the timer does not seem to work correctly on the page as it is normally used (I assume it is being updated). On the local host, it works without problems. The code below is for an aspx file and an aspx.cs file

<asp:UpdatePanel ID="UpdatePanel2" runat="server"> <ContentTemplate> <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick"> </asp:Timer> <div class="form-area"> <div class="clock"> <p><img id="c-time" src="images/clock.png"/>Current Time <span class="spanclass"> <asp:Label ID="CurrentTimeLabel" runat="server" Text="Label"> </asp:Label> </span> </p> </div> <p id="text"> <asp:Label ID="Processing" runat="server" Text="Label"></asp:Label> <br /> <asp:Label ID="FilterLabel" runat="server" Text="Label"></asp:Label> <br />Time Left for list to Refresh <span class="spanclass"> <asp:Label ID="TimeLeftLabel" runat="server" Text=""></asp:Label> </span> </p> </div> <div class="clear"></div> </ContentTemplate> </asp:UpdatePanel> 

and for aspx.cs

 protected void Timer1_Tick(object sender, EventArgs e) { CurrentTimeLabel.Text = DateTime.Now.ToShortTimeString(); if (SecondsLeft > 0) { SecondsLeft--; } else if (MinutesLeft > 0) { MinutesLeft--; SecondsLeft = 59; } if (SecondsLeft < 10) TimeLeftLabel.Text = " 0" + MinutesLeft + ":" + "0" + SecondsLeft; else TimeLeftLabel.Text = " 0" + MinutesLeft + ":" + SecondsLeft; if (MinutesLeft == 5) { FilterLabel.Text = ""; } if (MinutesLeft == 0 && SecondsLeft == 0) { function(); } } 

Thanks in advance. Looking forward to help

+6
source share
2 answers

I agree with Ovidiu. Try it in javascript with jQuery.

 $(document).ready(function(){ setInterval(function () {Counter() }, 1000); }); var count= 0; function Counter() { count++; $('#testLabel').html(count); } 
+1
source

Do you have a ScriptManager control on the page?

+1
source

Source: https://habr.com/ru/post/957667/


All Articles