How do you force Visual Studio to regenerate the .

2019-01-01 06:46发布

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

30条回答
余生无你
2楼-- · 2019-01-01 06:49

I had this problem and for me, I had a space in one of my ID values for one of my controls. I took the space out and the designer file regenerated itself.

查看更多
公子世无双
3楼-- · 2019-01-01 06:50

Most of the solutions here don't work if you're running Visual Studio 2013 and possibly 2012. Microsoft probably introduced some optimizations to make the IDE snappier, consequently they've reduced the number of cases that trigger the code generator. The following scenarios that used to work no longer do:

  1. Delete the aspx or ascx file -- No longer checks for this case
  2. Cut all the content and repaste into the aspx or ascx file -- No longer works, no change in the references
  3. Convert to Web Application -- Option no longer available
  4. Arbitrarily changing content on the aspx/ascx file -- No longer works (see 2).

The solution is surprisingly simple, but it's slightly cumbersome. In order to trigger the code generator, change something that would require the designer.aspx.cs to be generated. Changing content that doesn't affect code, such as a CSS style or adding text, won't trigger the code generator. You must change a referenced control. Here's how to do it:

In the ascx or aspx change the ID of the control

<asp:HyperLink ID="MyLink" runat="server" NavigateUrl="~/Default.aspx" Text="Home" />

to

<asp:HyperLink ID="theLINK" runat="server" NavigateUrl="~/Default.aspx" CssClass="tab" Text="Home" />

Go to the ascx.cs or aspx.cs and make sure you rename all references to "MyLink" to "theLINK" as well. Save and do build and the you should be good to go.

查看更多
步步皆殇っ
4楼-- · 2019-01-01 06:52

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!

查看更多
梦该遗忘
5楼-- · 2019-01-01 06:52

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.

查看更多
无色无味的生活
6楼-- · 2019-01-01 06:55

Delete the designer.cs file and then right click on the .aspx file and choose "Convert To Web Application". If there is a problem with your control declarations, such as a tag not being well-formed, you will get an error message and you will need to correct the malformed tag before visual studio can successfully re-generate your designer file.

In my case, at this point, I discovered that the problem was that I had declared a button control that that was not inside of a form tag with a runat="server" attribute.

查看更多
不再属于我。
7楼-- · 2019-01-01 06:56

This is a bug in the IDE; I've seen it since VS 2003. THe solution is simple though.

Save your files. Completely exit the IDE (make sure the process stops, task mgr.)

Reopen the solution, dirty the markup, save. Fixed.

查看更多
登录 后发表回答