TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sachin Rathore
1.6k
153
1.4k
How to use a countdown timer for one page server only for (2 :55)
Oct 1 2020 12:52 AM
<asp:ScriptManager ID=
"ScriptManager1"
runat=
"server"
>
</asp:ScriptManager>
<asp:UpdatePanel ID=
"UpdatePanel1"
runat=
"server"
>
<ContentTemplate>
<asp:Timer ID=
"Timer1"
runat=
"server"
Interval=
"1000"
OnTick=
"Timer1_Tick"
>
</asp:Timer>
<asp:Label ID=
"Label1"
runat=
"server"
Text=
""
></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(Session[
"CountdownTimer"
] ==
null
)
{
Session[
"CountdownTimer"
] =
new
CountDownTimer(TimeSpan.Parse(
"00:02:55"
));
(Session[
"CountdownTimer"
]
as
CountDownTimer).Start();
}
}
protected
void
Timer1_Tick(
object
sender, EventArgs e)
{
if
(Session[
"CountdownTimer"
] !=
null
)
{
Label1.Text = (Session[
"CountdownTimer"
]
as
CountDownTimer).TimeLeft.ToString();
string
GetTime = Label1.Text;
string
[] Array = GetTime.Split(
':'
);
string
Minutes = Array[1];
string
Seconds = Array[2];
if
(Convert.ToInt32(Minutes) == 00 && Convert.ToInt32(Seconds) == 30)
{
//boxid.Enabled = false;
//boxid.ReadOnly = true;
}
else
if
(Convert.ToInt32(Minutes) == 0 && Convert.ToInt32(Seconds) == 0)
{
Session[
"CountdownTimer"
] =
new
CountDownTimer(TimeSpan.Parse(
"00:02:55"
));
(Session[
"CountdownTimer"
]
as
CountDownTimer).Start();
//boxid.Enabled = true;
//boxid.ReadOnly = false;
}
}
}
public
class
CountDownTimer
{
public
TimeSpan TimeLeft;
System.Threading.Thread thread;
public
CountDownTimer(TimeSpan original)
{
this
.TimeLeft = original;
}
public
void
Start()
{
// Start a background thread to count down time
thread =
new
System.Threading.Thread(() =>
{
while
(
true
)
{
System.Threading.Thread.Sleep(1000);
TimeLeft = TimeLeft.Subtract(TimeSpan.Parse(
"00:00:01"
));
}
});
thread.Start();
}
}
I am using this code but it is not working according to my requirement.
My Requirement the countdown timer for eg:- Timer is open 10 devices and 20 devices(mobile and laptop from differenr I.P.). the timer is same all the time. run only 2 minute 55 second (5 second pause) is it possible so please help me (ASP.NET C#)
Reply
Answers (
2
)
Showing two tables fields in one view best way
resetfull API with json result