Designer.cs not updating when new controls added t

2019-01-11 10:17发布

I've added a new control to my aspx files and noticed that not only was the new control not added to the designer file but that it was also missing quite a few other controls that were added by other members of the team. I've tried deleting the designer.cs file and using "Convert to Web Application" with no success. Some other things i've tried have been excluding the aspx from the project, building, and then re-including with no success. I've also manually entered in a control that was missing in the designer into the designer. When I run after do so an error appears saying the control isn't defined, even though it actually is, and that I should check if I'm missing a directive.

The first control I added was copy and paste from a similar control and made necessary changes. But, i've also tried manually creating the control with the same results.

Any ideas?

11条回答
何必那么认真
2楼-- · 2019-01-11 11:08

Close Visual Studio, then delete Temporary ASP.NET Files from C:\Windows\Microsoft.Net\Framework\Your_.Net_Version\ProjectName Delete the folder ProjectName and re-start Visual Studio. I had a similar issue some time ago and it was solved by these actions.

If you use IIS, you may need to stop the server/site to be able to delete the temp files.

查看更多
\"骚年 ilove
3楼-- · 2019-01-11 11:09

I've been suffered this problem in my work.

The surest thing is you regenerate your .designer.cs file, and here is the solution:

  • Locate the corrupted aspx.designer.cs file through the Solution Explorer
  • Delete only the designer.cs file from your project
  • Rightclick your main aspx file and select “Convert to Web Application“.
查看更多
劫难
4楼-- · 2019-01-11 11:10

I did this in VS2012:

  1. Open the page.aspx.designer.cs Find a control declaration of the same type of control (ie LinkButton)
  2. Copy it to the end of the file (before the end of class curly bracket)
  3. Rename the control variable to match the name of your control.

That's it.

查看更多
祖国的老花朵
5楼-- · 2019-01-11 11:11

I was able to solve the problem only manually adding the control declaration inside the code behind file. Every time I tried to regenerate the design.cs file, VS 2013 would write the same lines without the missing control.

The declaration needs to be added in the code behind, NOT in the design.cs, because it would be deleted each time the .aspx is changed.

Just add the declaration like you would do for any other variable, something like this:

protected MyNameSpace.MyControl ControlName;
查看更多
Viruses.
6楼-- · 2019-01-11 11:12

Just to add to the list of possible solutions: These lines in my markup file, although seemingly valid, were apparently causing a disconnect with the designer file:

<%: Styles.Render("/my-file.css") %>
<%: Scripts.Render("/my-file.js") %>

I simply commented them out, saved, and the designed file began working correctly. I then uncommented both lines, saved, and was able to add new controls to the page without issue. I found this strange, and it's still unclear to me what the initial cause of the problem was. I can only speculate that it's a Visual Studio bug.

Point being, there may be perfectly valid code that's causing an issue, in which case, a possible solution would be to go through commenting HTML sections out in your markup file until the designer file resolves itself, and then you can undo all your commenting and resume working as normal.

查看更多
登录 后发表回答