Visual Studio does not update the ASP.NET designer.cs file

Being a .NET developer, I spend a lot of time in Visual Studio (I changed the default shell in Windows once from explorer.exe to devenv.exe for a while, but that’s another story!) and, like all major software products, it has a few bugs in it here and there.

One of these bugs that gets annoying very quickly is that every once in a while it will stop updating the designer.cs file for an ASP.NET page.

A little bit of background on this first though. When you create an aspx page in Visual Studio, you’re given 3 files. One for the markup that you write, one for the code that you write, and one that VS generates to allow you to use the controls from the markup in your class. At compile time, the 2 code files are combined in to one class, and then the page gets compiled on first run into a class that inherits from your previous class. It is not the same class as the one you created. This is important to remember, because not every control that you have declared on the page needs to be in the code-behind file. The runtime will create any controls that are in the markup whether they have any supporting code or not. While this may seem like a good feature, it just makes it harder to analyse and debug this problem!

Say you have a page with some controls on it, and you add another textbox or 2. All of a sudden, for no apparent reason, you can’t access these textboxes from the code behind file. They don’t exist and even when you type their names in it fails to compile. What do you do then? Restarting VS doesn’t seem to do anything, even restarting Windows doesn’t fix it!

There’s some questions on StackOverflow about this, so I’ve tried all of the different tricks. The one that seems to work consistently (and so has my upvote) is 1) Change into designer mode, 2) make a change (just modify some text or something) 3) save the file.

I’m hoping that knowing this saves everyone as much time as it’s going to save me!

Published 20 May 2009 11:02 by Mat Steeples

Filed under: ,

Comments

# re: Visual Studio does not update the ASP.NET designer.cs file@ 28 June 2009 21:38

I beleive this is caused when updating the website on two different computers, causing the sln file to become unsynchronised.

Mik

# re: Visual Studio does not update the ASP.NET designer.cs file@ 28 June 2009 21:40

Duplicate the site and then use the new one.  This should solve it.

Mik

# re: Visual Studio does not update the ASP.NET designer.cs file@ 28 July 2009 06:42

Great Tip !!! Keep up the great work Mate!!!!

Nripin

# re: Visual Studio does not update the ASP.NET designer.cs file@ 16 September 2009 14:55

Worked for me - thanks, Mat!

Jenn

Leave a Comment

(required) 
(required) 
(optional)
(required)