Code Bye

button点击事件的问题?,急求

protected void Page_Load(object sender, EventArgs e)
{
System.Timers.Timer t = new System.Timers.Timer(120000);
t.Elapsed += new System.Timers.ElapsedEventHandler(Timer_TimesUp);
t.Enabled = true;
}
private void Timer_TimesUp(object sender, System.Timers.ElapsedEventArgs e)
{
//button1.PerformClick();
btnSearch.Click += new EventHandler(btnSearch_Click);
btnSearch_Click(null, null);
}
public DataTable gcs()
{
DataTable mydt = bll.jsbx();
return mydt;

}
protected void btnSearch_Click(object sender, EventArgs e)
{
DataTable mdt=gcs();
if(mdt.Rows.Count>0)
{
Application.Lock();
Application[“wx”] = 1;
Application.UnLock();
//System.Web.HttpContext.Current.Response.Write(“<script>init()</script>”);
System.Web.HttpContext.Current.Response.Write(“<script type=”text/javascript”>window.parent.location.href=”../main.aspx”;</script>”);
//System.Web.HttpContext.Current.Response.Write(“<script language=”javascript” defer>top.leftFrame.location.href=”main.aspx”</script>”);
gvClass.DataSource = mdt;
gvClass.DataBind();
}
}
直接点击button可以刷新页面,但是两分钟刷新提示System.Web.HttpContext.Current.Response.Write(“<script type=”text/javascript”>window.parent.location.href=”../main.aspx”;</script>”);未将对象引用设置到对象的实例?

解决方案

40

按照下面修改(看红字),将就着可以运行
System.Timers.Timer t=null;
protected void Page_Load(object sender, EventArgs e)
{
t = new System.Timers.Timer(120000);
             t.Elapsed += new System.Timers.ElapsedEventHandler(Timer_TimesUp);
t.Enabled = true;
System.Threading.Thread.Sleep(5000);

}
private void Timer_TimesUp(object sender, System.Timers.ElapsedEventArgs e)
{
//button1.PerformClick();
btnSearch.Click += new EventHandler(btnSearch_Click);
btnSearch_Click(null, null);
  t.Enabled=false;
         }
public DataTable gcs()
{
DataTable mydt = bll.jsbx();
return mydt;

}
protected void btnSearch_Click(object sender, EventArgs e)
{
DataTable mdt=gcs();
if(mdt.Rows.Count>0)
{
Application.Lock();
Application[“wx”] = 1;
Application.UnLock();
//System.Web.HttpContext.Current.Response.Write(“<script>init()</script>”);
System.Web.HttpContext.Current.Response.Write(“<script type=”text/javascript”>window.parent.location.href=”../main.aspx”;</script>”);
//System.Web.HttpContext.Current.Response.Write(“<script language=”javascript” defer>top.leftFrame.location.href=”main.aspx”</script>”);
gvClass.DataSource = mdt;
gvClass.DataBind();
}
}


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明button点击事件的问题?,急求