Implementing Timer Functionality in Online Test Application
-
I am using Ajax Timer control in my OnlineTest Application. suppose if exam duration 45 mintes means i am adding 45 minutes to server time and i am subtracting with current server time and i will get 45 minutes with that i am reducing time in the form of seconds like 45:59,45:58. I am using ASP.Net 2.0,Ajax1.0, MS Access Database. but during postback means if i click on "Next" button(next question will appear in the next page) that time i am not able to maintain time what ever time it has taken during postback again from that i am able to continue again..please could u help me regard in this this is my aspx page <asp:UpdatePanel runat="server" ID="uppnlTimer" RenderMode="Inline" UpdateMode="Conditional"> <triggers> <asp:AsyncPostBackTrigger ControlID="tmrTest" EventName="Tick" /> </triggers> <contenttemplate> <asp:Timer ID="tmrTest" runat="server" OnTick="tmrTest_Tick" Interval="1000"> </asp:Timer> <asp:Label runat="server" ID="lblStartTime" Text="Start Time:" CssClass="lbl" /> <asp:Label runat="server" ID="lblStartTimeValue" CssClass="lblbold" /> <asp:HiddenField ID="hid_Ticker" runat="server" Value="0" /> </contenttemplate> </asp:UpdatePanel> this is Code behind code protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataSet dsServerTime = new DataSet(); DataSet dsExamTime = new DataSet(); dsServerTime = objOnlineTestPaperBAL.GetServerTime(); dsExamTime = objOnlineTestPaperBAL.GetServerTimeWithExamDuration(ExamTime); if (dsServerTime.Tables[0].Rows.Count > 0) { string serverTime = dsExamTime.Tables[0].Rows[0]["ExamTime"].ToString(); minutes = Convert.ToInt32(serverTime); hid_Ticker.Value = new TimeSpan(Hours, minutes, seconds).ToString(); if (Session["time"] != null) { string time = (string)Session["time"]; string[] str1 = time.Split(':'); minutes = Convert.ToInt32(str1[1]); seconds = Convert.ToInt32(str1[2]); lblStartTimeValue.Text = Convert.ToString(minutes) + " : " + Convert.ToString(seconds); hid_Ticker.Value = new TimeSpan(Hours, minutes, seconds).ToString();
-
I am using Ajax Timer control in my OnlineTest Application. suppose if exam duration 45 mintes means i am adding 45 minutes to server time and i am subtracting with current server time and i will get 45 minutes with that i am reducing time in the form of seconds like 45:59,45:58. I am using ASP.Net 2.0,Ajax1.0, MS Access Database. but during postback means if i click on "Next" button(next question will appear in the next page) that time i am not able to maintain time what ever time it has taken during postback again from that i am able to continue again..please could u help me regard in this this is my aspx page <asp:UpdatePanel runat="server" ID="uppnlTimer" RenderMode="Inline" UpdateMode="Conditional"> <triggers> <asp:AsyncPostBackTrigger ControlID="tmrTest" EventName="Tick" /> </triggers> <contenttemplate> <asp:Timer ID="tmrTest" runat="server" OnTick="tmrTest_Tick" Interval="1000"> </asp:Timer> <asp:Label runat="server" ID="lblStartTime" Text="Start Time:" CssClass="lbl" /> <asp:Label runat="server" ID="lblStartTimeValue" CssClass="lblbold" /> <asp:HiddenField ID="hid_Ticker" runat="server" Value="0" /> </contenttemplate> </asp:UpdatePanel> this is Code behind code protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataSet dsServerTime = new DataSet(); DataSet dsExamTime = new DataSet(); dsServerTime = objOnlineTestPaperBAL.GetServerTime(); dsExamTime = objOnlineTestPaperBAL.GetServerTimeWithExamDuration(ExamTime); if (dsServerTime.Tables[0].Rows.Count > 0) { string serverTime = dsExamTime.Tables[0].Rows[0]["ExamTime"].ToString(); minutes = Convert.ToInt32(serverTime); hid_Ticker.Value = new TimeSpan(Hours, minutes, seconds).ToString(); if (Session["time"] != null) { string time = (string)Session["time"]; string[] str1 = time.Split(':'); minutes = Convert.ToInt32(str1[1]); seconds = Convert.ToInt32(str1[2]); lblStartTimeValue.Text = Convert.ToString(minutes) + " : " + Convert.ToString(seconds); hid_Ticker.Value = new TimeSpan(Hours, minutes, seconds).ToString();
If I understood your question correctly, you do not want to penalize the user for the time it takes the Page to PostBack. Why don't you add an
OnClick()
event to the Next button to capture the time remaining and send it to a Session variable, first, before calling the next question, etc. Then once the page has posted back you can retrieve the time remaining from the Session variable?Regards, Gary