views:

497

answers:

2

Hey all,

As I'm working on a asp.net/c# project, I'm confronted with the foobar.aspx.designer.cs that auto generates it's content. eg, when I'm changing the code/designer, the designer.cs automatically updates it's content.

As I'm bit of a control-dude, I'd like to maintain the code myself. I'm not happy with the overkill of comments I don't need. Like:

    /// <summary>
    /// Form1 control.
    /// </summary>
    /// <remarks>
    /// Auto-generated field.
    /// To modify move field declaration from designer file to code-behind file.
    /// </remarks>
    protected global::System.Web.UI.HtmlControls.HtmlForm Form1;

While I'd like to see the following:

    protected global::System.Web.UI.HtmlControls.HtmlForm Form1;
    protected global::System.Web.UI.WebControls.Button Button3;
    etc, etc

(don't mind the naming, ofcourse I'd give it some distinguishing nameing)

How to fix this? I checked google on this one, but couldn't find an answer so quickly...

A: 

You could read the comments, they tell you what to do.

Move the declarations to your codebehind and delete the designer file.

But I have to make an observation:

Expression of this kind of concern and especially the expenditure of effort in trying to undo the kindness that VS is showing you belies a degree of naiveté and inexperience.

Perhaps your time would be better spent coding? ;-)

Sky Sanders
But then, for example, when I add another textbox, will there be no designer file created?
Joris
I think what @code poet means is that you completely stop adding controls in ASPX (markup). Only add controls through code behind. Then no designer file will be created since you never touch your markup file again.
scherand
@Joris - ok, make up your mind; are you a control freak who wants to control his markup and codebehind or are you a typical who likes to occasionally drag-n-drop controls from the tool box to the *DESIGNER*? ;-)
Sky Sanders
About coding... I'd rather go coding instead of drag-n-drop. I forgot to tell, but the reason why I want to control it myself, and code the design myself, is because the designer fails at usability. It's sometimes really a pain in the ass to add a simple textbox along with others in a formdiv, while adding a "hardcoded" textbox is (in this case) much simpler (and because of that, also faster)... @scherland - ok, that's a good one, except I can't use the designer anymore. which is still very handy sometimes...
Joris
+1  A: 

I am not sure if you can disable the automatic generation of this file. Nor if it would be good idea to do so... If you really want (need?) to interfere with it I would rather look for a way to change its behaviour/format. Unfortunately I cannot provide a solution/hint for this either. You might have to look in the field of "custom tools" (for code generation) though.

Why are you so unhappy with the format of the file? I almost never even look at it :) And according to Scott Guthrie the designer file has been introduced in VS 2005 as "a place where Visual Studio is allowed to write 'ugly' code": Tutorial 2: Code-Behind with VS 2005 Web Application Projects.

Edit: Maybe this article by Scott Hanselman could be of any help? T4 (Text Template Transformation Toolkit) Code Generation - Best Kept Visual Studio Secret.

scherand