At times while developing an ASP.NET project you may run into the following error in your code behind file:
The name ‘controlName’ does not exist in the current context
Often this is simply a case of a misnamed control or an error in your .aspx file. Other times, however, the problem can be due to an invalid designer.cs file.
Usually when you modify an .aspx file Visual Studio will update the accompanying designer.cs file with any new controls which have been added or modified. I emphasize usually because at times the designer.cs file doesn’t update at all. You can create and update all the controls you’d like but it makes absolutely no difference.
Regenerating the Designer.cs File
In these cases I’ve found regenerating the designer.cs file to the best route to take. Nobody wants to, or should have to, modify the designer.cs file by hand. Regenerating the file only takes two simple steps:
- Delete the current designer.cs file
- Right click on the .aspx file and choose Convert to Web Application
That’s it! And it was so obvious all along…