How to use a timer control without page postback event in asp.net

Posted by Artisingh30 under Regular Expressions on 3/3/2011 | Points: 10 | Views : 5812 | Status : [Member] | Replies : 3
hi
I want to use a timer control in my test.aspx page. i have a start button, when click on start, timer's enable property is set true mode.and when i click on stop button timer's enable property should be false so that timer can stop.since i have a text box on page and after clicking start button there should generate random number and after each minute duration it should display on text box but during this period page should not be post back.My problem is this ,how to use timer so that it work and page would also not post back during this process.
Thanks.




Responses

Posted by: Prabhakar on: 3/3/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi Artisingh30,

Check this code ..
private static FileStream fs = new FileStream(@"c:\temp\mcb.txt", FileMode.OpenOrCreate, FileAccess.Write);
private static StreamWriter m_streamWriter = new StreamWriter(fs);

Now write the following code on the Form Load event:

private void Form1_Load(object sender, System.EventArgs e)
{
// Write to the file using StreamWriter class
m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
m_streamWriter.Write(" File Write Operation Starts : ");
m_streamWriter.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(),DateTime.Now.ToLongDateString());
m_streamWriter.WriteLine(" ===================================== \n");
m_streamWriter.Flush();
}

private void timer1_Tick(object sender, System.EventArgs e)
{
m_streamWriter.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(),DateTime.Now.ToLongDateString());
m_streamWriter.Flush();
}

Best Regard's
Prabhakar

Artisingh30, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 3/4/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Timer object wil do a event trigger and it goes for postback...

Thanks
Karthik
www.f5Debug.net

Artisingh30, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhu.b.rokkam on: 3/6/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Javascript would be the best option for your requirement.. Use the SetTimeOut function of javascript

Thanks and Regards
Madhu

Artisingh30, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response