ASP.NET/AJAX - 计时器不工作正确的 [英] ASP.NET/AJAX - Timer not working correct
问题描述
我努力让你看到一个Ajax倒计时器的web应用。每当我按下一个按钮倒计时应该回到30并保持倒计时。
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.
现在,问题是每当我推计时器保持计数到2秒或2和大部分时间后,该计时器保持站在30为长
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.
web窗体code:
WebForm code:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="geen verbinding"></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<br />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
<asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick">
</asp:Timer>
</form>
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;
}
希望有人知道是什么问题,如果有无论如何要解决这个问题。
Hope somebody knows what the problem is and if there is anyway to fix this.
在此先感谢!
推荐答案
但问题是,Visual Studio中承载它在localhost。如果您使用本地主机的IP-联系地址127.0.0.1而不是在URL中,它的工作速度快。我想这会不会对更快的机器出现问题,sadfully我有没有在那个时候。
The problem was that Visual Studio hosted it on localhost. If you use ip-adress 127.0.0.1 instead of local host within the URL it worked fast. I guess this won't be a problem on faster machines, sadfully I had none at that time.
编辑:添加一个赏金对这一问题是个错误,我们对此深感抱歉。
Adding a bounty on this question was a mistake, sorry about that.
这篇关于ASP.NET/AJAX - 计时器不工作正确的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!