如何使用c#在asp.net中实现倒数计时器 [英] How to implement countdown timer in asp.net using c#
本文介绍了如何使用c#在asp.net中实现倒数计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个在线测试应用程序。所有测试都是定时的。持续时间是60分钟..我想实现倒数时间,减少秒。在我的页面的某个地方应该显示剩余时间。如59:59,59:58,59:57 ... 60分钟结束后,测试应自动提交。在60分钟之前我们也可以提交测试。
解决方案
检查这些博客
http://www.askdavetaylor.com/how_do_i_create_a_javascript_countdown_timer_on_my_web_page.html [ ^ ]
http://stackoverflow.com/questions/4151532/how-to-make-a-countdown-timer-in-asp-net-web-applicationc [ ^ ]
--NDK
您可以使用ajax控件来使用Timer Control
< asp:timer id = Timer1 runat = server interval = 1000 ontick = Timer1_Tick xmlns:asp = #unknown > < / asp:timer >
< asp :lable id = Lable1 runat = server xmlns:asp = #unknown / >
在cs文件中添加ontick事件代码:
protected void Timer1_Tick( object sender,EventArgs e)
{
int 秒;
if (Convert.ToString(Label1.Text)!= )
{
seconds = int .Parse(Label1.Text);
}
else
{
seconds = Convert.ToInt32(defaultTimer); // 在默认计时器中设置一些时间计数
}
会话[timeout ] =(秒 - 1).ToString();
if(seconds> 0)
{
Label1.Text =(seconds - 1).ToString();
}
else
{
Timer1.Enabled = false;
}
}
使用Java Script浏览倒计时器的链接
这里 [ ^ ]
Hi,
I am developing an on line test application. All test are timed. Duration is 60 minutes.. I want to implement countdown time which decreases by seconds. Somewhere on my page time remaining should be displayed. Like 59:59, 59:58, 59:57... After 60 mins is over the test should automatically be submitted. Before 60 mins also we can also submit the test.
解决方案
check these blogs
http://www.askdavetaylor.com/how_do_i_create_a_javascript_countdown_timer_on_my_web_page.html[^]
http://stackoverflow.com/questions/4151532/how-to-make-a-countdown-timer-in-asp-net-web-applicationc[^]
--NDK
You can use Timer Control by using ajax controls
<asp:timer id="Timer1" runat="server" interval="1000" ontick="Timer1_Tick" xmlns:asp="#unknown"></asp:timer> <asp:lable id="Lable1" runat="server" xmlns:asp="#unknown" />
Add ontick event code in cs file:
protected void Timer1_Tick(object sender, EventArgs e) { int seconds; if (Convert.ToString(Label1.Text) != "") { seconds = int.Parse(Label1.Text); } else { seconds =Convert.ToInt32(defaultTimer);//set some time count in default timer } Session[timeout"] = (seconds - 1).ToString(); if (seconds> 0) { Label1.Text = (seconds - 1).ToString(); } else { Timer1.Enabled = false; } }
Go through the link for Countdown timer using Java Script
Here[^]
这篇关于如何使用c#在asp.net中实现倒数计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文