我继承了一个早在.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的东西吗?
发布于 2010-12-22 02:38:01
我相信添加部分类的时候是ASP.NET 2.0。在此之前,所有设计器代码都必须包含在后台代码中。现在,其中一些代码被分隔在一个分部类中,这样就不会弄乱您的代码。
我不知道您是如何创建新页面的,但是只要新的初始化代码还在运行,我就不认为您需要坚持使用此代码。
https://stackoverflow.com/questions/4502614
复制相似问题