locked
Close session on Online Test RRS feed

  • Question

  • User1669525285 posted

    Hi

    I have created a template for online test, which has a time duration in minutes. Different test would have different time limit.

    And i want to expire the session or end the test or give an alert message when the time ends and also notify few minutes before time ends.

    Any suggestion or help?

    Thanks 

    Amit

    Friday, November 16, 2012 1:06 AM

Answers

  • User1669525285 posted

    Anyways, got help from link below to get the time left:

    http://stackoverflow.com/questions/3733227/javascript-seconds-to-minutes-and-seconds

      function DisplaySessionTimeout() {
                var sessionTimeout = $('#ctl00_contentPlaceHolder1_hdnSecondsLeft').val();
    
                //assigning minutes left to session timeout to Label
                var hours = Math.floor(sessionTimeout / 3600);
                var time = sessionTimeout - hours * 3600;
                var min = Math.floor(time / 60);
                var sec = time % 60;
    
                if (hours < 10) {
                    hours = "0" + hours;
                }
    
                if (min < 10) {
                    min = "0" + min;
                }
    
                if (sec < 10) {
                    sec = "0" + sec;
                }
    
                $('#ctl00_contentPlaceHolder1_lblSessionTime').text(hours + ":" + min + ":" + sec);
                //sessionTimeout;
                sessionTimeout = sessionTimeout - 1;
                $('#ctl00_contentPlaceHolder1_hdnSecondsLeft').val(sessionTimeout);
    
                //if session is not less than 0
                if (sessionTimeout >= 0)
                //call the function again after 1 minute delay
                    window.setTimeout("DisplaySessionTimeout()", 1000);
                else if (sessionTimeout == 60) {
                    //show message box
                    alert("Your test will end in 1 minute.");
                }
                else {
                    //show message box
                    alert("Your current Session is over.");
                }
            }

    Above is the final code i came up with and it works!!!



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 16, 2012 4:59 AM

All replies

  • User1648350404 posted

    i want to expire the session

    You can redirect to another page using javascript and on the page_load:

    protected void Page_Load(object sender, EventArgs e)
        {
            Session.Abandon(); 
    FormsAuthentication.SignOut(); 
    FormsAuthentication.RedirectToLoginPage();
            
           // Response.Redirect(clsCommon.value("login.aspx?mode=logout");
        }



    give an alert message when the time ends and also notify few minutes before time ends.

    check following:

    http://www.codeproject.com/Articles/24669/JavaScript-to-Show-Session-Timeout-Counter

    Friday, November 16, 2012 1:29 AM
  • User1669525285 posted

    Thanks fr the reply!

    What if i want to change on every second.

    Lets say, time limit is 20 minutes and the counter should goes like :

    19:59

    19:58

    19:57

    .

    .

    .

    .

    00:02

    00:01

    Time Over!

    Friday, November 16, 2012 1:51 AM
  • User1669525285 posted

    Anyways, got help from link below to get the time left:

    http://stackoverflow.com/questions/3733227/javascript-seconds-to-minutes-and-seconds

      function DisplaySessionTimeout() {
                var sessionTimeout = $('#ctl00_contentPlaceHolder1_hdnSecondsLeft').val();
    
                //assigning minutes left to session timeout to Label
                var hours = Math.floor(sessionTimeout / 3600);
                var time = sessionTimeout - hours * 3600;
                var min = Math.floor(time / 60);
                var sec = time % 60;
    
                if (hours < 10) {
                    hours = "0" + hours;
                }
    
                if (min < 10) {
                    min = "0" + min;
                }
    
                if (sec < 10) {
                    sec = "0" + sec;
                }
    
                $('#ctl00_contentPlaceHolder1_lblSessionTime').text(hours + ":" + min + ":" + sec);
                //sessionTimeout;
                sessionTimeout = sessionTimeout - 1;
                $('#ctl00_contentPlaceHolder1_hdnSecondsLeft').val(sessionTimeout);
    
                //if session is not less than 0
                if (sessionTimeout >= 0)
                //call the function again after 1 minute delay
                    window.setTimeout("DisplaySessionTimeout()", 1000);
                else if (sessionTimeout == 60) {
                    //show message box
                    alert("Your test will end in 1 minute.");
                }
                else {
                    //show message box
                    alert("Your current Session is over.");
                }
            }

    Above is the final code i came up with and it works!!!



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 16, 2012 4:59 AM