Roy r

Roy r

  • NA
  • 64
  • 168.3k

Timer1_Tick not firing

Apr 19 2011 1:27 AM
 I have two textboxs and one timer on my contet page.

In timer onTick event I am changing the text of Textbox2 to System.DateTime.Now.Second.

protected void Timer1_Tick(object sender, EventArgs e)
{
TextBox2.Text = System.DateTime.Now.Second.ToString();
Timer1.Enabled = false;
}

Initially timer is enabled so TextBox2 will fill initially.Then timer will Stop.

Now I want to enable timer,when user start typing in TextBox1. So I wrote following code..

protected void Page_Load(object sender, EventArgs e)
{
 TextBox1.Attributes.Add("onkeypress", "myfunction()");
}


function myfunction() {
var timer = Sys.Application.findComponent("<%= Timer1.ClientID %>");

//returns the timer's interval in milliseconds:
var waitTime = timer.get_interval;

//sets the timer's interval to 5000 milliseconds (or 5 seconds):
timer.set_interval(3000);

//returns whether or not the timer is enabled:
var isTimerEnabled = timer.get_enabled();

//disables the timer:
timer.set_enabled(true);

//starts the timer:
timer._startTimer();

//stops the timer:
//timer._stopTimer();
}

Now I after 3 seconds page will do postback but Timer1_Tick will not call.

Any one knows why this is happening ?


Answers (7)