我正在尝试在 asp.net 中创建一个计时器
Public Class _Default
Inherits System.Web.UI.Page
Dim min As Integer
Dim sec As Integer
Dim hr As Integer
Dim totalTime As Integer
Dim timerStr As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
totalTime = 5340
hr = Math.Floor(totalTime / 3600)
min = 30
sec = totalTime Mod 60
timerStr = String.Format("{0:00}:{1:00}:{2:00}", hr, min, sec)
label1.Text = timerStr
End Sub
Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs)
Display()
label1.Text = timerStr
End Sub
Protected Sub Display()
totalTime -= 1
hr = Math.Floor(totalTime / 3600)
sec = totalTime Mod 60
If sec = 0 Then
min = (totalTime / 60) Mod 60
End If
timerStr = String.Format("{0:00}:{1:00}:{2:00}", hr, min, sec)
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Display()
label1.Text = timerStr
End Sub
End Class
//更新面板代码
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick">
</asp:Timer>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"
RenderMode="Inline">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Label ID="label1" runat="server"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
现在根据代码计时器每秒调用一次但它没有发生我尝试使用按钮和单击事件但仍然文本没有更新但当我点击按钮时页面刷新。我做错了什么吗?