Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.designer.cs what is it for?

In my project when I create a webusercontrol or a webform it creates the code behind, but it also creates a .ascx.designer.cs file.

What is this file for? Can I prevent it from being added when I create a new webform/webusercontrol?

like image 708
raklos Avatar asked Jun 30 '09 09:06

raklos


2 Answers

In .NET 1.x, the code that allowed the Visual Studio designer to create a visual representation of the page was included within the code behind file itself. It was usually encapsulated within a region called "Designer generated code". (IIRC!)

New developers often inadvertently made changes to those code sections causing problem when working in design view or compilation errors.

In .NET 2+, with the advent of partial classes, M$ was able to extract that portion of code into a separate partial class that would not interfere with the code written by the developer. This file is usually named as Designer.vb/cs. You should not delete it for the same reasons mentioned above.

like image 148
Cerebrus Avatar answered Oct 11 '22 14:10

Cerebrus


This is normally the IDE-generated code that sets up the form (which you configure by drag-n-drop or inserting values into property windows). Probably not such a good idea to get rid of it since your application would need it (unless you plan to handcode everything).

like image 37
jpoh Avatar answered Oct 11 '22 14:10

jpoh