locked
How to show Count down time on online exam web application in asp.net c# RRS feed

  • Question

  • User-235689633 posted

    Hiii,

    i want to show count down time when user click on start exam button timer start with count down how many minutes left.

    if time finished user can not click on next button he comes on result page

    when admin add sets of question he fill the text filled with 60 minutes or 45 minutes or 90 minutes admin will decide.

    for example set1 time duration 60 minutes 10 questions of every sets he will make multiple sets with different minutes

    please help. its urgent

    thanks in advance

    Monday, March 24, 2014 2:10 AM

Answers

  • User-1818759697 posted

    Hi,

    If you want to use a timer to display the count down time online, you could refer to the following example:

        <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <div>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:Label ID="Label1" runat="server" Text="TimeLeft:"></asp:Label>
                    <asp:Label ID="Label2" runat="server" Text=""></asp:Label>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="Timer1"  />
                </Triggers>
            </asp:UpdatePanel>
            <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick"></asp:Timer>
        </div>
        </form>
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace Testing
    {
        public partial class WebForm61 : System.Web.UI.Page
        {
            static  int hh, mm, ss;
            
            static  double TimeAllSecondes = 5;
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void Timer1_Tick(object sender, EventArgs e)
            {
                if (TimeAllSecondes > 0)
                {
                    TimeAllSecondes = TimeAllSecondes - 1;
                }
    
                TimeSpan time_Span = TimeSpan.FromSeconds(TimeAllSecondes);
                hh = time_Span.Hours;
                mm = time_Span.Minutes;
                ss = time_Span.Seconds;
    
                Label2.Text = "  " + hh + ":" + mm + ":" + ss;
            }
    
        }
    }

    With the above codes,  it will post request each seconds. Too frequently request to server is not a good idea and it will create much more overhead on the server. So we can use JavaScript to present the time.

    For detailed information, you could refer to:

    http://forums.asp.net/t/1291427.aspx?how+to+create+a+countdown+timer+using+C+and+ASP+NET+AJAX+

    Regards

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 24, 2014 11:34 PM
  • User-1404016747 posted

    Check out this post I made earlier.
    http://forums.asp.net/post/5650351.aspx

    Should be easy enough to modify to your needs.

    20 equals how many seconds to count down from.

    <body onload="startCountdown(20);">
    <html>
    <head>
    <title></title>
    <script>
        function startCountdown(timeLeft) {
            var interval = setInterval( countdown, 1000 );
            update();
    
            function countdown() {
                if ( --timeLeft > 0 ) {
                    update();
                } else {
                    clearInterval( interval );
                    update();
                    completed();
                }
            }
    
            function update() {
                hours   = Math.floor( timeLeft / 3600 );
                minutes = Math.floor( ( timeLeft % 3600 ) / 60 );
                seconds = timeLeft % 60;
    
                document.getElementById('time-left').innerHTML = '' + hours + ':' + minutes + ':' + seconds;
            }
    
            function completed() {
                // Do whatever you need to do when the timer runs out...
            }
        }
    </script>
    </head>
    <body onload="startCountdown(20);">
    Timer is up in <span id="time-left"></span>
    </body>
    </html>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 24, 2014 11:40 PM

All replies

  • User724169276 posted

    Hello Chawla,

    Try this link:

    http://www.codeproject.com/Questions/260124/Countdown-timer-in-asp-net

    Monday, March 24, 2014 4:03 AM
  • User-1818759697 posted

    Hi,

    If you want to use a timer to display the count down time online, you could refer to the following example:

        <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <div>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:Label ID="Label1" runat="server" Text="TimeLeft:"></asp:Label>
                    <asp:Label ID="Label2" runat="server" Text=""></asp:Label>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="Timer1"  />
                </Triggers>
            </asp:UpdatePanel>
            <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick"></asp:Timer>
        </div>
        </form>
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace Testing
    {
        public partial class WebForm61 : System.Web.UI.Page
        {
            static  int hh, mm, ss;
            
            static  double TimeAllSecondes = 5;
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void Timer1_Tick(object sender, EventArgs e)
            {
                if (TimeAllSecondes > 0)
                {
                    TimeAllSecondes = TimeAllSecondes - 1;
                }
    
                TimeSpan time_Span = TimeSpan.FromSeconds(TimeAllSecondes);
                hh = time_Span.Hours;
                mm = time_Span.Minutes;
                ss = time_Span.Seconds;
    
                Label2.Text = "  " + hh + ":" + mm + ":" + ss;
            }
    
        }
    }

    With the above codes,  it will post request each seconds. Too frequently request to server is not a good idea and it will create much more overhead on the server. So we can use JavaScript to present the time.

    For detailed information, you could refer to:

    http://forums.asp.net/t/1291427.aspx?how+to+create+a+countdown+timer+using+C+and+ASP+NET+AJAX+

    Regards

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 24, 2014 11:34 PM
  • User-1404016747 posted

    Check out this post I made earlier.
    http://forums.asp.net/post/5650351.aspx

    Should be easy enough to modify to your needs.

    20 equals how many seconds to count down from.

    <body onload="startCountdown(20);">
    <html>
    <head>
    <title></title>
    <script>
        function startCountdown(timeLeft) {
            var interval = setInterval( countdown, 1000 );
            update();
    
            function countdown() {
                if ( --timeLeft > 0 ) {
                    update();
                } else {
                    clearInterval( interval );
                    update();
                    completed();
                }
            }
    
            function update() {
                hours   = Math.floor( timeLeft / 3600 );
                minutes = Math.floor( ( timeLeft % 3600 ) / 60 );
                seconds = timeLeft % 60;
    
                document.getElementById('time-left').innerHTML = '' + hours + ':' + minutes + ':' + seconds;
            }
    
            function completed() {
                // Do whatever you need to do when the timer runs out...
            }
        }
    </script>
    </head>
    <body onload="startCountdown(20);">
    Timer is up in <span id="time-left"></span>
    </body>
    </html>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 24, 2014 11:40 PM