用于在线试卷的ASP.NET中的CountDown计时器 [英] CountDown timer in ASP.NET for online exam paper

查看:45
本文介绍了用于在线试卷的ASP.NET中的CountDown计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在asp.net中创建一个在线考试aaplication。在这种情况下,我想在我的第一页创建倒数计时器,通过按钮点击开始(没有回发)。问题是当我点击按钮页面加载事件火和计时器不再工作。

今天我成功创建了一个页面,但是计时器从页面加载开始,这是不对的。

请帮我完整代码,因为我是这个编程领域的新手。

请给我第二页代码,以便用以前的时间计算启动计时器。

紧急帮助我............

解决方案

asp中的倒数计时器。网 [ ^ ]


源代码......

 <   center  >  
< ; div >
< asp:ScriptManager ID = SM1 runat = 服务器 > < / asp:ScriptManager >
< asp:Timer ID = timer1 < span class =code-attribute> runat = server

时间间隔 = 1000 OnTick = timer1_tick > < / asp:Timer >
< / div >

< div >
< asp:UpdatePanel id = updPnl

runat = < span class =code-keyword> server UpdateMode = 条件 >
< ContentTemplate >
< asp:标签 ID = lblTimer runat = server Font-Bold = True 字体名称 = Arial

字体 - 大小 = X-Large ForeColor = #6600CC > < / asp:Label >
< / ContentTemplate >
< 触发器 >
< asp:AsyncPostBackTrigger ControlID = timer1 EventName = tick / >
< / Triggers >
< / asp:UpdatePanel >
< / div < span class =code-keyword>>
< / center >





c#code .....


在页面加载中写这个....

  if (!SM1.IsInAsyncPostBack)

会话[ timeout ] = DateTime.Now.AddMinutes( 30 )。ToString();







定时点击...

<前lang =cs> 受保护 void timer1_tick( object sender,EventArgs e)
{
if 0 > DateTime.Compare(DateTime.Now,DateTime.Parse(Session [ timeout]。ToString())))
{
lblTimer.Text = string .Format( 剩余时间:00:{0}:{1},(( Int32 )DateTime.Parse(Session [ timeout]。ToString())。 Subtract(DateTime.Now).TotalMinutes).ToString(),(( Int32 )DateTime.Parse(Session [ timeout]。ToString())。Subtract(DateTime.Now).Seconds).ToString());
}
else
{
timer1.Enabled = true ;
Response.Redirect( Logout.aspx);

}
}







尝试这个,它会工作.............


I want to create a online exam aaplication in asp.net.In that case I want to create countdown timer on my first page which start by button click(without post back).The problem is when I click on button the page load event fire and timer not work anymore.
today I was successfully created a page but the timer start with page load,it's not right way.
Please help me with complete code because I am new in this programming field.
Please give me also second page code for start the timer with previous time calculation.
Urgent help me............

解决方案

Countdown timer in asp.net[^]


source code......

<center>
<div>
<asp:ScriptManager ID= "SM1" runat="server"></asp:ScriptManager>
<asp:Timer ID="timer1" runat="server"

Interval="1000" OnTick="timer1_tick"></asp:Timer>
</div>

<div>
<asp:UpdatePanel id="updPnl"

runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblTimer" runat="server" Font-Bold="True" Font-Names="Arial"

        Font-Size="X-Large" ForeColor="#6600CC"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="timer1" EventName ="tick" />
</Triggers>
</asp:UpdatePanel>
</div>
</center>



c# code.....

write this in page load....

if (!SM1.IsInAsyncPostBack)

                Session["timeout"] = DateTime.Now.AddMinutes(30).ToString();




for timer click...

protected void timer1_tick(object sender, EventArgs e)
       {
           if (0 > DateTime.Compare(DateTime.Now, DateTime.Parse(Session["timeout"].ToString())))
           {
               lblTimer.Text = string.Format("Time Left: 00:{0}:{1}", ((Int32)DateTime.Parse(Session["timeout"].ToString()).Subtract(DateTime.Now).TotalMinutes).ToString(), ((Int32)DateTime.Parse(Session["timeout"].ToString()).Subtract(DateTime.Now).Seconds).ToString());
           }
           else
           {
               timer1.Enabled = true;
               Response.Redirect("Logout.aspx");

           }
       }




try this,it will work.............


这篇关于用于在线试卷的ASP.NET中的CountDown计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆