什麼是相當於這些在asp? 它不適合我!定時器在Asp.net中打勾?
lbl_date.Text = FormatDateTime(Now, DateFormat.LongDate)
lbl_time.Text = FormatDateTime(Now, DateFormat.LongTime)
什麼是相當於這些在asp? 它不適合我!定時器在Asp.net中打勾?
lbl_date.Text = FormatDateTime(Now, DateFormat.LongDate)
lbl_time.Text = FormatDateTime(Now, DateFormat.LongTime)
這裏要記住的一點是,所有的VB代碼所做的就是產生一個HTML文件,並沒有別的。一旦完成了這個工作,你正在工作的頁面類甚至被髮送到垃圾收集器,並且你所處理的處理器線程被重新用於服務另一個http請求。因此,嘗試根據計時器事件設置標籤只是簡單的問題,您的計時器可能會在它有機會打勾之前處理掉。
相反,你想在JavaScript中做這個特定的工作。看看javascript的setTimeout()方法。
lbl_date.Text = DateTime.Now.ToLongDateString();
lbl_time.Text = DateTime.Now.ToLongTimeString();
ASP.NET中沒有定時器控件,而是AJAX定時器。
在你必須把AJAX更新面板內的這些標籤如下
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="2000" OnTick="Timer1_Tick">
</asp:Timer>
<asp:Label ID="lbl_date" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="lbl_time" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
,並在後面的代碼爲Timer1_Tick
事件把
lbl_date.Text = FormatDateTime(Now, DateFormat.LongDate)
lbl_time.Text = FormatDateTime(Now, DateFormat.LongTime)
這應該工作的話..
什麼是你的標題(「計時器滴答」)和問題(設置標籤文本)之間的關係? –