开发者

Regenerate designer.cs [duplicate]

This question already has answers here: How do you force Visual Studio to regenerate the .designer files for aspx/ascx files? (48 answers) Closed 9 years ago.

I just deleted a designer.cs file from a aspx page.. (D开发者_运维百科on't ask how I can do that.. You don't really want to know..) Is it a way to regenerate the file for the aspx page? I was hoping that something like "right-click/ generate designer" exists but it is not the case.. :-(

So thanks if somebody have an idea..


Find another solution to my Question, right-click on the aspx file, then choose "convert to web application" and then, the designer.cs file is regenerated..

It is more easier and quick..


This option is no longer available in VS2013, but you can accomplish the same thing by selecting your project in the Solution Explorer, then going to the Project option on the Menu Bar. Near the bottom you will see the Convert to Web Application option. This will generate designer files for all the *.aspx pages in your project that don't have them, but be aware that this may not be what you want if you have a mix of CodeFile *.aspx pages and CodeBehind files. This will also convert CodeFile pages to CodeBehind files. (Courtesy Joisey Mike)


Open the designer and save (you might have to change something in the markup before being able to save). It should be recreated. Event subscriptions and other settings only kept in the designer won't be possible restore though.

EDIT: Make sure that the designer file exists by creating an empty file with just the partial class definition. Also make sure that it's registered in the project file. Then open the designer or the aspx page and make one small change (insert a space in the aspx) and save it. Now the designer file should be recreated.


Use R-Studio from http://www.r-tt.com and undelete it. Use Source Control in the future.

Part from that, try copying the GUI controls into a new page and copy the content of its Designer page to your deleted one.


If editing and saving your aspx file doesn't work, try the following:

  1. Restart Visual Studio
  2. Ensure there are no errors in your aspx file (e.g. missing <%@ Register ... %> tags)

Having ReSharper installed helps with step 2 as it prompts to automatically register missing user controls (but in my case, only after a restart).

This worked for me in Visual Studio 2008.


View in browser should recreate it.


Along with all the other suggestions:

In my case, it was a user control that began missing it's designer file. So, in the ascx, I commented out all the content, leaving only the Assembly,Register, and Import headers. I then rebuilt the solution. With that success, I had new designer code auto generated. I removed the comments and rebuilt again. Everything was back in the place it should be.

Your mileage may vary.


Edit: It should be able to recreate it somehow. However my tip still stands: use source control. Some time in the future, you will delete something vital and can't restore it via any means, and then you will be grateful for having source control.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜