Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 148909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:02:33+00:00 2026-05-11T09:02:33+00:00

I have a countdown timer in javascript that is called by a code behind

  • 0

I have a countdown timer in javascript that is called by a code behind using asp.net VB. I cannot find a way to keep track of the time ,.

the problem is., I cannot get the time that elapsed after postback so that the timer would continue ticking,. can you help me please,.?? I would really appreciate it.,

here is my code fragment:

asp.net VB codebehid

    on page load{         If Page.IsPostBack = True Then             ClientScript.RegisterClientScriptBlock(Me.GetType, 'timer_script',            '<script language='javascript'>function mySubmit()</script>')              ClientScript.RegisterStartupScript(Me.GetType, 'timer_script',              '<script>countdown_clock();</script>')         End If          If Page.IsPostBack = false Then             TimerTxtbx.Text = '00:06:10'   'hour:min:sec -> initialize timer             ClientScript.RegisterClientScriptBlock(Me.GetType, 'timer_script',            '<script language='javascript'>function mySubmit()</script>')              ClientScript.RegisterStartupScript(Me.GetType, 'timer_script',              '<script>countdown_clock();</script>')         End If     }      on button click{         NextBtn.Attributes.Add('onclick', 'mySubmit()')   'call a javascript function          ClientScript.RegisterStartupScript(Me.GetType, 'timer_script',          '<script>countdown_clock();</script>')     } 

javascript code:

function mySubmit() {     document.getElementById('TimerTxtbx').removeAttribute('disabled'); }      function countdown_clock() {                        var current_time;     current_time = document.getElementById('TimerTxtbx').value;       var hours = current_time.substring(0,2);     var minutes = current_time.substring(3,5);     var seconds = current_time.substring(6,8);        var n_seconds;     var n_minutes = minutes;     var n_hours = hours;      if (seconds == 0)     {        n_seconds = 59;         if (minutes == 0)         {         n_minutes = 59;             if (hours == 0){             alert('Time is up');             return;             }                 else{                    n_hours = hours - 1;                if (n_hours < 10)                    n_hours = '0' + n_hours;                 }             }         else         {             n_minutes = minutes - 1;             if (n_minutes < 10)                 n_minutes = '0' + n_minutes;         }     }     else     {         n_seconds = seconds - 1;         if (n_seconds < 10)             n_seconds = '0' + n_seconds;     }         document.getElementById('TimerTxtbx').value = n_hours + ':' + n_minutes + ':' + n_seconds;        setTimeout('countdown_clock()',1000); //function call and delay by 1sec        document.getElementById('TimerTxtbx').setAttribute('disabled','disabled');       }//end function 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T09:02:34+00:00Added an answer on May 11, 2026 at 9:02 am

    I think your problem is that you have to undisable the textbox when you submit, otherwise the text doesn’t get tracked in the viewstate.

    This code works for me:

    <form id='form1' runat='server'> <div>     <asp:TextBox ID='TimerTxtbx' runat='server' />     <asp:Button runat='server'  OnClientClick='mySubmit()'/> </div> </form> 

    With code behind:

        protected void Page_Load(object sender, EventArgs e)     {         ClientScript.RegisterStartupScript(typeof (Page), 'timer_script',                                            '<script>countdown_clock();</script>');          if (!IsPostBack)         {             TimerTxtbx.Text = '00:00:10';         }     } 

    Update based on yours:

    The problem is that you are setting the OnClientClick property of your button in the Click event handler for your button.

    This basically means it won’t have any effect until the button is clicked, and then it isn’t useful to you.

    Set the OnClientClick somewhere like OnInit or Page_Load, or just do it in the aspx like in my example. Does this makes sense to you? When you click the button the OnClientClick property must have already been set.

    If you’re going to do any ASP.NET stuff, you really want to readup and really get to know the page lifecycle. Starting points:

    • http://www.15seconds.com/issue/020102.htm
    • http://msdn.microsoft.com/en-us/library/ms178472.aspx
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer userlevel.label maybe? May 11, 2026 at 11:45 pm
  • Editorial Team
    Editorial Team added an answer You don't need to use SQL. Just call Drupal's file_create_path('myfile.pdf')… May 11, 2026 at 11:45 pm
  • Editorial Team
    Editorial Team added an answer you can use the Response.StatusCode property to return a 404:… May 11, 2026 at 11:45 pm

Related Questions

I have the following code: def show @game = $site.new_game_of_type(params[:id]) @game.start end def update_game_time
I'm trying to make a countdown timer in my app. I already know the
I'm using jQuery Countdown plugin to implement a Countdown and call a webservice when
I had this idea of creating a count down timer, like 01:02, on the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.