Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
I need a code for putting a timer on aN ASP.NET page to check the time as you write an examination online. The code should be in Vb.net. And postback shouldn't restart the timer

[edit]SHOUTING removed - OriginalGriff[/edit]
Posted
Updated 1-Mar-13 0:13am
v2
Comments
OriginalGriff 1-Mar-13 6:13am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.
OsoJames 1-Mar-13 6:24am    
Sorry, i've been frustrated by the one i am working on. Just need help
Sorry

 
Share this answer
 
Comments
OsoJames 1-Mar-13 6:27am    
Thanks for the help and i'm sorry for shouting and being rude
Karthik Harve 1-Mar-13 6:28am    
That is ok. happy coding .!!
OsoJames 2-Mar-13 8:10am    
Thanks for the great help, i was able to devise another way of making the timer through the resource links you made available.
Thank You
Karthik Harve 2-Mar-13 8:24am    
Welcome.!
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!
 
Share this answer
 
Comments
OsoJames 1-Mar-13 6:26am    
Anyway thanks for the correction. Didn't realise how loud i was, at least you heard me. :)
Now this is the way I solved it with the help given me above by Karthik:

VB
Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

       Dim timer_arr() As String
       Dim timer As String
       timer = Button1.Text

       timer_arr = timer.Split(":")
       Session("seconds") = Integer.Parse(timer_arr(2))
       Dim minutes = Integer.Parse(timer_arr(1))
       Dim hours = Integer.Parse(timer_arr(0))
       If Session("seconds") = 0 And minutes = 0 And hours = 0 Then
           Timer1.Enabled = False
       Else
           Session("seconds") = Session("seconds") - 1
       End If
       If (Session("seconds") < 0) Then
           Session("seconds") = 59
           Session("minutes") = Session("minutes") - 1
       End If
       If Session("minutes") < 0 Then
           Session("Minutes") = 59
           Session("TimerRemaining") = Session("TimerRemaining") - 1
       End If

       Button1.Text = Session("TimerRemaining").ToString() & ":" & Session("Minutes").ToString & ":" & Session("Seconds").ToString

       If Session("TimerRemaining") = 0 And Session("minutes") = 0 And Session("seconds") = 0 Then
           Button1.Enabled = False
           Timer1.Enabled = False
       End If
   End Sub



VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


        If Not IsPostBack Then
            Session("TimerRemaining") = 1
            Session("Minutes") = 0
            Session("Seconds") = 0
            Button1.Text = Session("TimerRemaining").ToString() & ":" & Session("Minutes").ToString & ":" & Session("Seconds").ToString
        End If
   End Sub



XML
<form id="form1" runat="server">

                        <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:Button ID="Button1" runat="server" Text="Button" />
                <asp:Timer ID="Timer1" runat="server" Interval="1000">
                </asp:Timer>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900