启动System.timers.timer后,未获取文本框值 [英] After starting System.timers.timer, not getting textbox value

查看:83
本文介绍了启动System.timers.timer后,未获取文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我遇到了一个问题,我在asp.net中创建了一个页面.实际上,此页面将由用户填充.页面太长,即页面有很多控件.有时,会话在用户填充此页面时过期.或由于RTO(请求超时)服务器问题.为避免此问题,我创建了一个临时表,该表将在一段时间后根据计时器控制(System.timers.timer)间隔进行更新.但是,问题是,当我在单击按钮时启动计时器时,在触发计时器的已发生事件后,我没有得到该页面上任何文本框控件的值.另一方面,当我先在所有文本框中填充值,然后启动计时器后,便会获取所有文本框的值.请给我一些有关此问题的建议.请帮助我.我的代码是.. ...

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();
    	}



谢谢
(Rahul)



Thanks
(Rahul)

推荐答案

您可以查看
You can have a look at this article[^], it has a script which prevents session timeout.


这篇关于启动System.timers.timer后,未获取文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆