protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
UpdateTime();
}
}
protected void Timer1_Tick(object sender, EventArgs e)
{
UpdateTime();
}
public void UpdateTime()
{
try
{
int hour = 00, min = 00, sec = Int32.Parse(Session["tleft"].ToString());
// min = Int32.Parse(Session["tleft"].ToString()) /
TimeSpan span = new TimeSpan(TimeSpan.TicksPerSecond * sec);
string str = span.Hours.ToString("00") + ":" + span.Minutes.ToString("00") + ":" + span.Seconds.ToString("00");
int tleft = Int32.Parse(Session["tleft"].ToString()) - 1;
if (tleft <= 0)
{
Response.Redirect("result.aspx");
}
// timeleft.Text = tleft.ToString();
timeleft.Text = str.ToString();
Session["tleft"] = tleft.ToString();
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
}
-----------------------------------------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TickTock.aspx.cs" Inherits="TickTock" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" >
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div>
<asp:Label ID="timeleft" runat="server" ></asp:Label>
<asp:Timer ID="Timer1" Enabled="true" runat="server" Interval="1000"
ontick="Timer1_Tick" >
</asp:Timer>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" />
</Triggers>
</asp:UpdatePanel>
</form>
</body>
</html>
jatinmca 0 Newbie Poster
JorgeM 958 Problem Solver Team Colleague Featured Poster
jatinmca 0 Newbie Poster
Sathish_3 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.