Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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();
    	}


Thanks
(Rahul)
Posted

1 solution

You can have a look at this article[^], it has a script which prevents session timeout.
 
Share this answer
 
Comments
Rahul saraswat 18-Jun-12 6:21am    
no,please tell me only that How can i get value of all controls on that page after starting timer. When I start timer before filling all textbox values, i dont get text of any textBox after fired of Elapsed event. when i start timer after filling all contols on page, i get all values of all controls after firing Elapsed event.

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