Designer.cs not updating when new controls added to .aspx

末鹿安然 提交于 2019-11-27 13:11:22
Marinha do Nascimento

Try this

1.- Change CodeBehind="Name.aspx.cs" to CodeFile ="Name.aspx.cs"

2.- Build

3.- Change CodeFile ="Name.aspx.cs" to CodeBehind ="Name.aspx.cs"

Jiangong SUN

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“.

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.

To replace the designer file in VS 2013:

  1. Delete the old *.designer.cs file
  2. select the *.aspx file
  3. Select “Convert to Web Application“ from the Project top drop-down bar

One simple/stupid mistake that also results in similar symptoms is if you copy aspx and aspx.cs files and rename them, but neglect to update the references inside the file.

I came across this question trying to find the temp asp.net directory, but clearing that didn't help. I then realized that I did not update CodeFile="Page.ascx.cs" after I had copied the files to create a new modified version of the page. Then i was trying to add a control and reference it in PageModified.ascx.cs but kept saying it didn't exist.

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.

This also seems to happen when you have a usercontrol that references another usercontrol in the same namespace. if you move the referenced user control to a different namespace the problem goes away

Sometimes there might be errors in html like two controls having the same Id. Also be careful with div and span tags. These stops the designer from getting updated. For all of these, check the warnings in Error List and fix them. You are ready to go. This solved my issue.

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;

For me the solution was to:

Put your page in design view and right click / refresh. It will sync the controls with the designer.cs. Make sure designer.cs is close before doing this.

Source

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.

In my case, I had to add the runat="server" attribute then to rebuild the solution. The missing elements were automatically added to the generated aspx.designer.cs and become available for use in code

<button runat="server" id="Button01" type="button" class="Button" onclick="location.href='http://http://www.example.com/';">
   <asp:Label runat="server" Text='<%# GetText("Button01")%>'></asp:Label>
</button>

My designer.vb code file was not updating because of an error in Telerik web controls - I had an incorrect value in the DataKeyNames attribute of a MasterTableView. The aspx editor did not pick this up at design time as it's simply a string value, but it was causing the autogeneration of the designer.vb file to fail.

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