2010-12-21 88 views
0

我已经继承了.NET 1.0中写入的ASP.NET/C#项目。我开始使用.NET 2.0进行编程,因此一些过时的概念是陌生的。我注意到,该网页的80%,有下面的代码片段或类似的东西:组件设计器在后面的代码中生成代码

#region Component Designer generated code 

    //Required by the Web Services Designer 
    private IContainer components = null; 

    /// <summary> 
    /// Required method for Designer support - do not modify 
    /// the contents of this method with the code editor. 
    /// </summary> 
    private void InitializeComponent() 
    { 
    connSQL = new System.Data.SqlClient.SqlConnection(); 
    connSQL.ConnectionString = Inventory.Properties.Settings.Default.connectionString; 
    } 

    /// <summary> 
    /// Clean up any resources being used. 
    /// </summary> 
    protected override void Dispose(bool disposing) 
    { 
    if(disposing && components != null) 
    { 
    components.Dispose(); 
    } 
    base.Dispose(disposing); 
    } 

    #endregion 

虽然这个区域在页面加载过程中撞,注释掉它具有在网页上没有明显的影响。我可以猜测,如果connSQL对象被使用并且没有在其他地方初始化,那么问题就会出现,但事实并非如此。所以,我的问题是这个设计器生成的代码来自哪里?我从来没有看到它背后的代码。这是另一个.net 1.0的东西吗?

回答

2

我相信当部分类被添加时,它是ASP.NET 2.0。在此之前,所有设计器代码都必须包含在后面的代码中。现在,这些代码中的一部分以分部类分隔,因此它不会混淆您的代码。

我不知道你是如何创建你的新页面,但只要新的init代码工作,我不认为你需要挂在这个代码。