用于在线测试的计时器刷新整个页面 [英] Timer used for Online test refreshing the whole page

查看:100
本文介绍了用于在线测试的计时器刷新整个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个在线测试系统。

我用定时器控件开发了一个定时器。

问题是当我开始测试时页面会自动刷新。

我想停止自动刷新计时器。







//.aspx code



I am developing an online test system.
I have developed a timer using timer control.
The problem is when I start the test the page is getting refreshed automatically.
I want to stop auto refresh of timer.



//.aspx code

<asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick"

                    Interval="1000">
<asp:Label ID="label_time"

                runat="server" Text=""></asp:Label>





//.aspx.cs代码



//.aspx.cs code

int totalSeconds = 0;
   int seconds = 0;
   int minutes = 0;
   string time = &amp;amp;quot;&amp;amp;quot;;



  protected void Page_Load(object sender, EventArgs e)
   {

           if (!Page.IsPostBack)
           {
               Session["time"] = 1800 ;


           }


      }


    protected void Timer1_Tick(object sender, EventArgs e)
   {
       Session["time"] = Convert.ToInt16(Session["time"]) - 1;
       if (Convert.ToInt16(Session["time"]) <= 0)
       {

          label_time.Text = "TimeOut!";
           insert_result();
           Response.Redirect("Show_result.aspx");
       }

       else
       {
           totalSeconds = Convert.ToInt16(Session["time"]);
            seconds = totalSeconds % 60;
            minutes = totalSeconds / 60;
            time = minutes + ":" + seconds;
           label_time.Text = time;
       }
   }

推荐答案

如果你正在使用时间控制,那么首先你需要在第一行停止你的计时器,然后写你要在计时器刻度事件中执行的行代码,之后你必须在最后一行启动计时器。



in你想要永久停止你的计时器,然后你必须写Timer1.Enabled = false;
If you are using time control then on tick event first of all you have to stop your timer in first line, then write line code which you want to execute in timer tick event, after that you have to start your timer in last line.

in between you want to stop your timer permanently, then you have to write Timer1.Enabled = false;


你好,



你应该使用UpdatePanel中的计时器而不是页面上的其他控件,如果可能的话请使用JavaScript计时器,这样每次都不会打到服务器上。



请看这个javascript代码: -



Hi,

You should use your timer in UpdatePanel other than other controls on your page and if possible please use JavaScript timer so that it will not hit the server every time.

Please see this javascript code:-

<html>
<head>
<title>Countdown</title>
<script type="text/javascript">
// set minutes
var mins = 5;

// calculate the seconds (don't change this! unless time progresses at a different speed for you...)
var secs = mins * 60;
function countdown() {
setTimeout('Decrement()',1000);
}
function Decrement() {
if (document.getElementById) {
minutes = document.getElementById("minutes");
seconds = document.getElementById("seconds");
// if less than a minute remaining
if (seconds < 59) {

seconds.value = secs;

} else {

minutes.value = getminutes();

seconds.value = getseconds();

}

secs--;

setTimeout('Decrement()',1000);

}

}

function getminutes() {

// minutes is seconds divided by 60, rounded down

mins = Math.floor(secs / 60);

return mins;

}

function getseconds() {

// take mins remaining (as seconds) away from total seconds remaining

return secs-Math.round(mins *60);

}

</script>
</head>
<body>

<div id="timer">
This is only valid for the next <input id="minutes" type="text" style="width: 14px; border: none; background-color:none; font-size: 16px; font-weight: bold;"> minutes and <input id="seconds" type="text" style="width: 26px; border: none; background-color:none; font-size: 16px; font-weight: bold;"> seconds.
</div>
<script>
countdown();
</script>

< br $>






谢谢





Thanks


这篇关于用于在线测试的计时器刷新整个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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