raklos
raklos

Reputation: 28545

.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?

Upvotes: 6

Views: 3808

Answers (2)

Cerebrus
Cerebrus

Reputation: 25775

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.

Upvotes: 4

jpoh
jpoh

Reputation: 4586

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).

Upvotes: 1

Related Questions