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
Within the Visual Studio:
1) Remove your aspx.designer.cs file
2) Right click on your aspx file and select "Convert to Web Application" This should add the aspx.designer.cs back and up to date.
If you get an error saying:
"Generation of designer file failed: The method or operation is not implemented."
Try close Visual Studio and then reopen your project and do step number two again
How to generate aspx.designer.cs in visual studio?
If you are like me and you add old .ASPX files to a more recent project. You are probably going to forget some of the controls used on the page.
If so, first thing, if there are multiple files you are installing; Fix one at a time first.
When you compile, fix errors generated. They will probably be the same errors in all the files.
Next, if you have Designer files, delete all of the inserted - designer files. Next, make sure there are not any other errors when you compile, other than the designer files.
Finally right click your web project and click on Convert to Web Application. This will insert the designer files you need.
These are the absolute best steps to fix the issues.
When you are in design view, right click on the screen and hit refresh.
I've encountered the same problem for years now, working in Visual Studio 2008. And I've tried every "solution" on StackOverflow and dozens of blogs, just like I'm sure all of you have. And sometimes they work, and sometimes they don't, just like I'm sure all of you have encountered. And apparently it's still an issue in VS2010 and VS2012.
So finally, a couple of months ago, I decided enough was enough, and over a few weeks I built a tool called "Redesigner" that generates .designer files. It's open-source under the BSD license, with the source code available on SourceForge — free to use, free to steal, free to do anything you please with. And it does what Visual Studio fails to do so often, which is generate .designer files quickly and reliably.
It's a stand-alone command-line tool that parses .aspx and .ascx files, performs all the necessary reflection magic, and spits out correct .designer files. It does all the parsing and reflection itself to avoid relying on existing code, which we all know too well is broken. It's written in C# against .NET 3.5, but it makes pains to avoid using even System.Web for anything other than type declarations, and it doesn't use or rely on Visual Studio at all.
Redesigner can generate new .designer files; and it offers a --verbose option so that when things go wrong, you get far better error messages than "Exception of type System.Exception was thrown." And there's a --verify option that can be used to tell you when your existing .designer files are broken — missing controls, bad property declarations, unreadable by Visual Studio, or otherwise just plain borked.
We've been using it at my workplace to get us out of jams for the better part of the last month now, and while Redesigner is still a beta, it's getting far enough along that it's worth sharing its existence with the public. I soon intend to create a Visual Studio plugin for it so you can simply right-click to verify or regenerate designer files the way you always wished you could. But in the interim, the command-line usage is pretty easy and will save you a lot of headaches.
Anyway, go download a copy of Redesigner now and stop pulling out your hair. You won't always need it, but when you do, you'll be glad you have it!
https://sourceforge.net/projects/redesigner/
TL;DR;
Edit the
Inherits
attribute of the ASPX page's@Page
directive and hit Save. Your designer file should be regenerated.Ensure that
Inherits
= <namespace>.<class_name> andCodeBehind
= <class_name>.aspx.csI was trying to do this on a Sharepoint 2010 project, using VS 2010 and TFS, and none of the solutions above worked for me. Primarily, the option, "Convert to Web Application" is missing from the right-click menu of the .ASPX file when using TFS in VS 2010.
This answer helped finally. My class looked like this:
And my
@Page
directive was (line-breaks here for clarity):I first changed the
Inherits
to MyProjects.Finance.Pages, hit Save, then changed it back to MyProjects.Finance.Pages.FinanceSubmission and hit Save again. And wallah! The designer page was regenerated!Hope this helps someone using TFS!
Convert to Web Application did not work for me.
Deleting designer.cs and pasting a blank designer.cs did not work either.
But yes this worked:
Done. New designer.cs generated. :)