Asp.net计时器和更新面板

jib*_*usa 6 c# asp.net updatepanel timer

嗨我已经在堆栈溢出搜索了很多,以找到我的问题的合适答案,但找不到它.我希望你们能解决我的问题.

我有一个Web应用程序,它有两个更新面板.

第一个更新面板仅包含一个定时器,其间隔仅为一秒,它充当倒计时器.

第二个更新面板是条件面板,仅在倒计时结束时更新.

我面临的问题是,当我发布我的Web应用程序时,计时器似乎无法正常工作在页面上的一些用户来到顶部(我假设它得到刷新).在本地主机上它完美无缺地运行.下面给出了aspx文件和aspx.cs文件的代码

<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>
Run Code Online (Sandbox Code Playgroud)

和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();
        }

    }
Run Code Online (Sandbox Code Playgroud)

提前致谢.期待着寻求帮助

Jer*_*erg 1

我同意奥维迪乌的观点。使用 jQuery 在 javascript 中尝试一下。

$(document).ready(function(){
  setInterval(function () {Counter() }, 1000);
 });

var count= 0;
function Counter() {
  count++;
  $('#testLabel').html(count);
}
Run Code Online (Sandbox Code Playgroud)