Timer.aspx
<div>
<asp:ScriptManager ID="SM1" runat="server">
</asp:ScriptManager>
<asp:Timer ID="timer1" runat="server" Interval="1000" OnTick="timer1_tick">
</asp:Timer>
</div>
<div>
<asp:UpdatePanel ID="updPnl" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblTimer" runat="server"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="timer1" EventName="tick" />
</Triggers>
</asp:UpdatePanel>
</div>
代码隐藏文件 Timer.aspx.cs
public partial class Timer : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!SM1.IsInAsyncPostBack)
Session["timeout"] = DateTime.Now.AddMinutes(11).ToString();
}
protected void timer1_tick(object sender, EventArgs e)
{
if (0 > DateTime.Compare(DateTime.Now,
DateTime.Parse(Session["timeout"].ToString())))
{
lblTimer.Text = "Time Left: " +
((Int32)DateTime.Parse(Session["timeout"].
ToString()).Subtract(DateTime.Now).TotalMinutes).ToString()+" minutes";
}
}
}
以下是Asp.net AJAX中10分钟计时器的代码。我在哪里编写弹出窗口的代码,当时间达到零时显示?