Regenerate designer.cs [duplicate]

眉间皱痕 提交于 2019-12-18 12:04:19

问题


I just deleted a designer.cs file from a aspx page.. (Don'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..


回答1:


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)




回答2:


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.




回答3:


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.




回答4:


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.




回答5:


View in browser should recreate it.




回答6:


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.




回答7:


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.



来源:https://stackoverflow.com/questions/5066564/regenerate-designer-cs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!