2

I am creating an online exam website and I want to set a 30 minute timer for 30 questions... Can anyone tell me how to use the timer control in asp.net or any other easy method?

4

4 回答 4

6
<asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick">
    </asp:Timer> // For one minute
<asp:UpdatePanel ID="UpdatePanel1"
    runat="server">
    <ContentTemplate>
        <asp:Label ID="Label1" runat="server"></asp:Label>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick">
        </asp:AsyncPostBackTrigger>
    </Triggers>
</asp:UpdatePanel>

protected void Timer1_Tick(object sender, EventArgs e)
{
    // Label1.Text = DateTime.Now.Second.ToString();
}
于 2017-03-09T18:06:07.617 回答
3

一种可能的方法是:

  • 创建一个 UpdatePanel,您将在其中插入每个问题和可能的答案
  • 在 UpdatePanel 中,您可以插入一个代表问题的 UserControl(例如,此 UserControl 将包含一个带有问题的标签和一些带有答案标签的单选按钮或复选框)
  • 在 UpdatePanel 中,您可以像在 Msdn http://msdn.microsoft.com/en-us/library/bb398865.aspx上的此示例中一样使用 Timer 控件 <asp:Timer id="Timer1" runat="server" Interval="120000" OnTick="Timer1_Tick"> </asp:Timer>
  • Timer 控件的 OnTick 事件中定义的函数将在每个时间间隔到期后在服务器端触发;在那里您将使用下一个问题的值加载 UserControl 并检查测试是否已完成或总时间是否已过(例如,通过将总已用时间求和到变量中)

如果需要,您还可以在页面中显示倒计时并使用 JavaScript 对其进行更新。

于 2012-06-14T11:55:38.110 回答
0

...或者您可以使用 JQuery。设置一个计时器(http://code.google.com/p/jquery-timer/),然后在最后触发一个计时动作。可以利用 Ajax 来尝试答案等 - 但这会将其他所有内容都保留在前端。

于 2012-06-14T12:01:29.840 回答
0

在更新面板中添加定时器控件是一种可以避免页面闪烁或页面总刷新的方法,用户可以获得流畅的体验。但是定时器控制效率低下,因为重复的请求被发送到服务器,这可能导致过载和不必要的资源浪费。AJAX 将是一个更好的选择,或者任何客户端 javascript 可能会更好。轮询是另一种有效的方法。

于 2019-06-11T07:10:09.570 回答