I am developing a web application where I need a timer down to count using ASP.NET
ASP: ScriptManager id = "Script Manager 1" Runat = "Server" & gt; & Lt; / ASP: ScriptManager & gt; & Lt; Asp: UpdatePanel ID = "Update Panel 1" Runat = "Server" & gt; & Lt; ContentTemplate & gt; & Lt; Asp: Label ID = "lblHour" text = "" runat = "server" & gt; & Lt; / Asp: label & gt; & Lt; ASP: label ID = "LBLMIN" text = "" runat = "server" & gt; & Lt; / Asp: label & gt; & Lt; Asp: Label ID = "lblSec" text = "" runat = "server" & gt; & Lt; / Asp: label & gt; & Lt; ASP: Timer ID = "Timer 1" Runat = "Server" Interval = "1000" ontic = "TimerTick" & gt; & Lt; / ASP: Timer & gt; & Lt; / ContentTemplate & gt; & Lt; / ASP: UpdatePanel & gt; Behind the code
Secure Zero Page_load (Object Sender, EventArgs e) {if (IsPostBack) {Session ["Time"] = DateTime Now .AddSeconds (40); }} Protected zero timer (object sender, event AGS E) {timespenn time 1 = new timespan (); Time 1 = (date time) session ["time"] - date time.Now; If (time 1.Seconds & lt; = 0) {lblSec.Text = "TimeOut!"; } And {lblSec.Text = time1.Seconds.ToString (); }} The problem I have is that the timer does not happen properly. It starts from 38, then goes to 35 and so on.
Is there any way to fix this problem?
I think this issue is here that when the timer starts, execute this code It does, after a while, a second, a second + some microseconds, this is the reason for this production. Check it in your code.
Secure Zero Page_load (object sender, event events e) {if (IsPostBack) {session ["time"] = date time.Now Edecand (40); }} Safe Wide TimerTit (Object Sender, EventEurge E) {var endtime = (datetime) session ["time"]; Var Endindie = ((Date Time) Session ["Time"]) Minute; Var endSec = ([date time] session ["time"]). second; Var endMsec = ((date time) session ["time"]). Millisecond; Var current time = date time.Now; Var currentMin = currentTime.Minute; Var currentSec = Current time. second; Var Current MSEC = Current Time. Millisecond; Var time 1 = end time - current time; LblHour.Text = string.Format ("and sec - {0}: {1}: {2}", and man, and SEC, and MSc); LblMin.Text = string.Format ("current stream - {0}: {1}: {2}", current, current SEC, current MSc); LblSec.Text = time1.Seconds & lt; = 0? "time up!" : Time1.Seconds.ToString (); }
Comments
Post a Comment