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 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:
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”
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”.