views:

231

answers:

2

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?

A: 

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

jpoh
A good intellectual excercise, but no, not generally recommended.
Matthew Scharley
+1  A: 

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.

Cerebrus
Heh, or VS would suddenly drop the event wiring, and you'd have no clue why Page_Load was no longer firing - even now VS sometimes gets confused on me and turns all my custom controls into generic System.Web.UI.Controls and then won't compile...
Zhaph - Ben Duguid
@Zhaph: You make me nostalgic... those were the days, lol!
Cerebrus