Rahul Sharma

Rahul Sharma

  • NA
  • 20
  • 9.4k

After starting System.timers.timer, not getting textbox value

Jun 18 2012 5:23 AM
Hi,
I am facing a problem.I have created a page in asp.net. Actually, this page will be filled by user. Page is too long i.e page has many controls. Sometimes, Session is expired while user is filling this page. or due to RTO(Request Timed Out) server problem. To prevent this problem, i have created a temporary table that will be updated after some time according to the timer control(System.timers.timer) interval. but, problem is that when i start timer on clickin a button, i dont get the value of any textbox control on that page after firing Elapsed event of timer. On the other way, when I fill values in all textboxes first and after that i start timer, then i get all textbox's values.Please give me some suggestion about this problem.Please help me.and my code is this .....

SqlConnection conn = new SqlConnection("Data Source=A-E7F834CA56374;Initial Catalog=company;Integrated Security=True");
SqlCommand cmd = new SqlCommand();
System.Timers.Timer timer = null;
    protected void StartTimer_Click(object sender, EventArgs e)
    {
        if (timer == null)
        {
            timer = new System.Timers.Timer(10000);
            timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
            timer.Enabled = true;
            timer.Start();
        }
    }
void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {       
            cmd.Connection = conn;
            conn.Open();
            cmd.CommandText = "Select * from employee where id='" + txtID.Text + "'";
            SqlDataReader dr = cmd.ExecuteReader();
            if (!dr.HasRows)
            {
                dr.Close();
                cmd.CommandText = "Insert into employee Values('" + txtID.Text + "','" + txtName.Text + "','" + txtSal.Text + "','" + txtDept.Text + "')";
            }
            else
            {
                dr.Close();
                cmd.CommandText = "Update employee set name='" + txtName.Text + "',salary='" + txtSal.Text + "',city='" + txtDept.Text + "' where id='" + txtID.Text + "'";
            }
            cmd.ExecuteNonQuery();
            conn.Close();           
    }
protected void StopTimer_Click(object sender, EventArgs e)
    {
        timer.Stop();
    }

Please help me as soon as possible.

Thanks
(Rahul)

Answers (1)