放在上面是声明为全局变量而放在Page_Load中,则只有在Page_Load中可用

解决方案 »

  1.   

    private simplesc=new simple();//放在这里,和放在Page_Load有什么不同?
                                      刷新页面对系统有无影响?
    页面刷新时不会触发这个函数的
     private void Page_Load(object sender, System.EventArgs e)
        {
            private simplesc=new simple();//每次都会执行    }
    每次刷新都会出发这个函数,可以用
     private void Page_Load(object sender, System.EventArgs e)
        {
       if(!page.IsPostBack)//如果是页面第一次调入
    {
            private simplesc=new simple();
    }
    else//已经调入,但重新请求服务器,比如刷新时或单击按钮等操作
    {
    //进行操作
    }
    这样就不会每次都执行
        }
      

  2.   

    also, the timing is different. The first statement is executed when the Page object is created and so you may not be able to access those intrinsic objects in Page object and you have to go through HttpContext.Current object, also, the Control hierarchy is not created yet