已经做好的窗体,修改时删除部分控件,再运行时就报错“未将对象引用设置到对象的实例“,而且实在Page_Load之前就报错,很奇怪,重启也无效,请大家帮帮忙

解决方案 »

  1.   

    检查 InitializeComponent()函数
      

  2.   

    删除控件时,未将后台服务器端定义控件的语句删除掉,检查InitializeComponent()函数中是否有未删除掉的控件定义语句
      

  3.   

    删除控件后把它相关的InitializeComponent()语句删除
      

  4.   

    你展开 折叠 的 自动生成的代码,有个private override void OnInit()函数
    看看里面有没有引用了你以删除的控件,有的话就删掉
      

  5.   

    你是在 [design] 环境下删除控件的么,还是在代码中删除的
      

  6.   

    展开 ”Web 窗体设计器生成的代码“,这里找哪个事件是没有用的
      

  7.   

    我在[design]环境下删除控件,然后再代码中删除相应程序。我检查了一下,”Web 窗体设计器生成的代码“,中涉及到的我的程序里都有
             #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.ds1 = new lvyou.ds();
    ((System.ComponentModel.ISupportInitialize)(this.ds1)).BeginInit();
    this.LinkButton2.Click += new System.EventHandler(this.LinkButton2_Click);
    this.LinkButton3.Click += new System.EventHandler(this.LinkButton3_Click);
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
    this.Button2.Click += new System.EventHandler(this.Button2_Click);
    this.Button3.Click += new System.EventHandler(this.Button3_Click);
    // 
    // ds1
    // 
    this.ds1.DataSetName = "ds";
    this.ds1.Locale = new System.Globalization.CultureInfo("zh-CN");
    this.Load += new System.EventHandler(this.Page_Load);
    ((System.ComponentModel.ISupportInitialize)(this.ds1)).EndInit();
    }
    #endregion还请各位帮忙看看
      

  8.   

    删除了很多控件,但保留的就只有Button1 Button2 Button3 LinkButton2  LinkButton3有相应click事件,还有个LinkButton1,是没有click的摆设。
      

  9.   

    你如果在代码页删除了控件,但是在vb里可能还保留那些声明
    如果你运行,就会报错你将
    #Region " Web 窗体设计器生成的代码 "
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        End Sub
        Protected WithEvents Label1 As System.Web.UI.WebControls.Label
       Private designerPlaceholderDeclaration As System.Object
        Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
            InitializeComponent()
        End Sub#End Region
    中相应代码删除
      

  10.   

    删除后,在aspx页面设计界面里保存一下,然后重新生成一下
      

  11.   

    我用的c#,InitializeComponent里面也没有删除的控件代码,真的是晕阿
      

  12.   

    private void InitializeComponent()
    {    
    this.ds1 = new lvyou.ds();
    ((System.ComponentModel.ISupportInitialize)(this.ds1)).BeginInit();
    this.LinkButton2.Click += new System.EventHandler(this.LinkButton2_Click);
    this.LinkButton3.Click += new System.EventHandler(this.LinkButton3_Click);
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
    this.Button2.Click += new System.EventHandler(this.Button2_Click);
    this.Button3.Click += new System.EventHandler(this.Button3_Click);
    // 
    // ds1
    // 
    this.ds1.DataSetName = "ds";
    this.ds1.Locale = new System.Globalization.CultureInfo("zh-CN");
    this.Load += new System.EventHandler(this.Page_Load);
    ((System.ComponentModel.ISupportInitialize)(this.ds1)).EndInit();
    }
    #endregion
    ->private void InitializeComponent()
    {
    try{    
    this.ds1 = new lvyou.ds();//在这加断点,单步执行,看看那出错?
    ((System.ComponentModel.ISupportInitialize)(this.ds1)).BeginInit();
    this.LinkButton2.Click += new System.EventHandler(this.LinkButton2_Click);
    this.LinkButton3.Click += new System.EventHandler(this.LinkButton3_Click);
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
    this.Button2.Click += new System.EventHandler(this.Button2_Click);
    this.Button3.Click += new System.EventHandler(this.Button3_Click);
    // 
    // ds1
    // 
    this.ds1.DataSetName = "ds";
    this.ds1.Locale = new System.Globalization.CultureInfo("zh-CN");
    this.Load += new System.EventHandler(this.Page_Load);
    ((System.ComponentModel.ISupportInitialize)(this.ds1)).EndInit();
    }
    catch( Exception ex )
    {
      //看看ex是什么?
    }
    }
    #endregion