How do you force Visual Studio to regenerate the .designer files for aspx/ascx files?

Glenn Slaven picture Glenn Slaven · Sep 5, 2008 · Viewed 314.3k times · Source

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

Answer

Espo picture Espo · Sep 5, 2008

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.