Sometimes when I'm editing page or control the .designer files stop being updated with the new controls I'm putting on the page. I'm not sure what's causing this to happen, but I'm wondering if there's any way of forcing Visual Studio to regenerate the .designer file. I'm using Visual Studio 2008
EDIT: Sorry I should have noted I've already tried:
- Closing & re-opening all the files & Visual Studio
- Making a change to a runat="server" control on the page
- Deleting & re-adding the page directive
I had this problem and for me, I had a space in one of my ID values for one of my controls. I took the space out and the designer file regenerated itself.
Most of the solutions here don't work if you're running Visual Studio 2013 and possibly 2012. Microsoft probably introduced some optimizations to make the IDE snappier, consequently they've reduced the number of cases that trigger the code generator. The following scenarios that used to work no longer do:
The solution is surprisingly simple, but it's slightly cumbersome. In order to trigger the code generator, change something that would require the designer.aspx.cs to be generated. Changing content that doesn't affect code, such as a CSS style or adding text, won't trigger the code generator. You must change a referenced control. Here's how to do it:
In the ascx or aspx change the ID of the control
to
Go to the ascx.cs or aspx.cs and make sure you rename all references to "MyLink" to "theLINK" as well. Save and do build and the you should be good to go.
Well I found a solution that works, though I don't really like it. I had to delete the .designer.cs file then recreate an empty file with the same name. When I went back in and saved the aspx file again, the designer file was re-generated.
Dodgy!
I use the following method which works everytime:
Recompile.
Delete the designer.cs file and then right click on the .aspx file and choose "Convert To Web Application". If there is a problem with your control declarations, such as a tag not being well-formed, you will get an error message and you will need to correct the malformed tag before visual studio can successfully re-generate your designer file.
In my case, at this point, I discovered that the problem was that I had declared a button control that that was not inside of a form tag with a runat="server" attribute.
This is a bug in the IDE; I've seen it since VS 2003. THe solution is simple though.
Save your files. Completely exit the IDE (make sure the process stops, task mgr.)
Reopen the solution, dirty the markup, save. Fixed.