Hi, I was wondering if there is a way of stoping the automatic code generation for form controls. I want to stop .NET creating the Text property (and only this property) for the "initializecontrol" function, so that I can do it myself later on in the initialization(the values will be different, depending on a user-defined language, e.g. English, Spanish). But, .NET keeps generating the code, even if I set it to nothing in the properties window.
Any ideas!?

Dani AI

Generated

Short answer: you cannot reliably suppress the designer so it omits a single property (like Text) while still using the Visual Studio/third‑party design surface. The designer writes declarations and property assignments from the markup and design‑time properties, and generated files are intended to be machine‑maintained. For who wants to control Text per language, the practical approaches are to avoid letting the designer hard‑code strings or to overwrite its value at runtime.

Common, practical fixes:

  • Set text at runtime. Let the designer create the control declarations, then assign localized values in code (Page_Init/Page_Load or PreRender) so the generated value is simply replaced. This is safe and preserves designer-managed files.
  • Use ASP.NET localization (resource files). Move all UI strings into App_GlobalResources or page local resources and use resource expressions or meta:resourcekey so values are resolved from .resx rather than being hardcoded into generated code.
  • Stop using the design surface for those controls. Edit the .aspx markup by hand and remove any Text attributes; avoid opening Design View because it often writes defaults back into generated files.

If you see duplicate declarations (as reported with IronSpeed): check for duplicate control IDs, stale or duplicate designer files, and whether the project is a Web Site vs Web Application (they handle generated fields differently). For Web Application projects you can delete the stale .designer file and let Visual Studio regenerate it (or use "Convert to Web Application"). For third‑party generators, review their output settings so they do not emit overlapping declarations.

Example: override in Page_Load

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        myLabel.Text = GetLocalizedString("WelcomeText");
    }
}

Caution: do not hand‑edit designer files for long‑term fixes; the designer/regenerator will overwrite them. Use resources or runtime assignment for robust, maintainable localization.

Recommended Answers

All 2 Replies

Not sure what the benefit is bacuse you can always customize or delete the Forms code. BUT... if all you want to do is start from scratch then simply create blank project and you can code away until your heart is content. Happy coding!

Hi,

I'm using Ironspeed Designer for designing ASP.NET pages quickly. The product is good. It uses a lot of user controls. I found a problem in the page design.

Whenever I click on page in design mode or at least, when I view the design of the page, automatically some code is generated. i.e. declarations for most of the controls are created again and it is giving build errors like.. there is already a definition for.... I know, this is the feature of ASP.NET. Is there anyway of stopping automatic code generation?

Thanks and regards,
mrc

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.