Component designer generated code in code behind
I have inherited an ASP.NET/C# project written way back in .NET 1.0. I started programming in .NET 2.0, so some of the antiquated concepts are foreign. I noticed that 80% of the pages have the following snippet or something similar:
#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
Although this area is hit in the page load process, commenting it out has no obvious effects on the web page. I can guess that if the connSQL object is used and not initialized elsewhere, then problems can come up, this just hasn't been the case. So, my question is where does this designer generated code come from? I've never 开发者_开发问答seen in it the code behind. Is this another .net 1.0 thing?
I believe it was ASP.NET 2.0 when partial classes were added. Before then, all the designer code had to be included in the code behind. Now, some of that code is separated in a partial class so it doesn't clutter up your code.
I don't know how you created your new pages, but as long as the new init code is working, I wouldn't think you need to hang on to this code.
精彩评论