<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Task3.Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <style type="text/css"> .auto-style1 { position: relative; top: 33px; left: 314px; width: 470px; height: 193px; } .auto-style2 { width: 202px; } </style> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="SM1" runat="server"></asp:ScriptManager> <asp:Timer ID="timer1" runat="server" Interval="1000" OnTick="timer1_tick" Enabled="False"> </asp:Timer> </div> <table class="auto-style1"> <tr> <td class="auto-style2"> <asp:Label ID="Label1" runat="server" Text="Enter Number of Minutes:"></asp:Label> </td> <td> <asp:TextBox ID="TextBox1" runat="server" TextMode="Number" Height="28px" Width="191px"></asp:TextBox> </td> </tr> <tr> <td class="auto-style2"></td> <td> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /> </td> </tr> <tr> <td class="auto-style2"> </td> <td> <div> <asp:UpdatePanel ID="updPnl" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Label ID="lblTimer" runat="server" Font-Size="X-Large"></asp:Label> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="timer1" EventName="tick" /> </Triggers> </asp:UpdatePanel> </div> </td> </tr> <tr> <td class="auto-style2"></td> <td> <asp:Label ID="lblresult" runat="server"></asp:Label> </td> </tr> </table> </form> </body> </html>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace Task3 { public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void timer1_tick(object sender, EventArgs e) { if (0 > DateTime.Compare(DateTime.Now, DateTime.Parse(Session["timeout"].ToString()))) { lblTimer.Text = "Number of Minutes Left: " + ((Int32)DateTime.Parse(Session["timeout"]. ToString()).Subtract(DateTime.Now).TotalMinutes).ToString(); } else { lblresult.Text = "Countdown Complete"; lblresult.ForeColor = System.Drawing.Color.Green; timer1.Enabled = false; } } protected void Button1_Click(object sender, EventArgs e) { timer1.Enabled=true; if (!SM1.IsInAsyncPostBack) { int time = int.Parse(TextBox1.Text)+1; Session["timeout"] = DateTime.Now.AddMinutes(time).ToString(); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)