本文介绍了用于在线测试的计时器刷新整个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在开发一个在线测试系统。 我用定时器控件开发了一个定时器。 问题是当我开始测试时页面会自动刷新。 我想停止自动刷新计时器。 //.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 codeint 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; } } 推荐答案 <html><head><title>Countdown</title><script type="text/javascript">// set minutesvar 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 remainingif (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 downmins = Math.floor(secs / 60);return mins;}function getseconds() {// take mins remaining (as seconds) away from total seconds remainingreturn 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> 谢谢Thanks 这篇关于用于在线测试的计时器刷新整个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-30 21:13