How to force Visual Studio to generate (or regenerate) your .designer file

I got stuck on a problem (related to the title of this post) today and thought I´d share my experiences (and how I solved it).
I had a class library project that I wanted to change into a web application project and copy some stuff from an old web application project that I had. That was done by editing the project file like this:





Just open a web application project and copy from that. No problem there really.

The Problem

The problem was when I started to add UserControls (ascx) and WebForms pages (aspx) to my “new” project from my old UI project. I dragged and dropped them into my new project and changed the namespaces and the inherits attributes. For some reason my old designer file got “messed up” and was placed under the aspx.cs file…long story short, it didn´t work and a had to delete it.
Looked like this with missing designer file:

When I tried to build the project in VS of course I got build errors like…

The name ‘Label1’ does not exist in the current context

…because of the missing designer file. How to get my designer file back then.

I started to search for the problem online and got some answers. Apparently you can force VS to generate your designer file by right clicking the aspx/ascx file and choose “Convert To Web Application”


And…nothing happened.

The Solution

After some digging I started to look at the markup which looked like this:


See anything strange? It´s missing the CodeBehind attribute. I added that back and tried again…and now it worked.


What also works in some situations is to first delete the designer file (.cs), not the code behind, and the save and close the solution file. Re-open it and then choose “Convert To Web Application” and the designer is the “fixed”.


, ,

  1. #1 by FP on December 9, 2009 - 13:01

    I have the same problem also adding the CodeBehind property!!!

  2. #2 by FP on December 9, 2009 - 13:02

    I have the same problem also adding the CodeBehind property!!!
    Nothing change

  3. #3 by Stephan Unrau on October 3, 2010 - 10:55

    To regenerate both the code behind and the designer files do this:

    1) Delete the designer file if it exists.
    2) Delete the code behind file if it exists (and you only want to do this if it’s empty obviously)
    3) Ensure that the page directive at the top of the aspx is something like this:

    4) Right click on the project for the web site and go to “convert to web application” – this will generate all the code behinds and designer pages automatically and fix up the page directive.

    At least that’s how I fixed my problem after a designer created several pages with Expression Web which did not create the codebehind pages.

    • #4 by Stephan Unrau on October 3, 2010 - 10:55

      Oh, and thanks for the tip!

      • #5 by Tanya Mironova on April 24, 2015 - 21:12

        Thanks. Very helpful

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: