How do you force Visual Studio to regenerate the .designer files for aspx/ascx files?
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
If you open the .aspx file and switch between design view and html view and back it will prompt VS to check the controls and add any that are missing to the designer file.
In VS2013-15 there is a Convert to Web Application command under the Project menu. Prior to VS2013 this option was available in the right-click context menu for as(c/p)x files. When this is done you should see that you now have a *.Designer.cs file available and your controls within the Design HTML will be available for your control.
PS: This should not be done in debug mode, as not everything is "recompiled" when debugging.
Some people have also reported success by (making a backup copy of your .designer.cs file and then) deleting the .designer.cs file. Re-create an empty file with the same name.
There are many comments to this answer that add tips on how best to re-create the designer.cs file.
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:
- Select all of the code-in-front (html markup etc) in the editor of the aspx/ascx file.
- Cut.
- Save.
- Paste.
- Save.
Recompile.