在 Visual Studio 2010 中更改网页后 Designer.cs 损坏

发布于 2025-01-07 23:25:33 字数 629 浏览 0 评论 0原文

当我在 aspx 文件中进行更改时,Visual Studio 行为不正常。它对 Designer.cs 文件进行更改。这些更改意味着我无法通过代码隐藏文件中的 ID 访问任何控件。

当我恢复在 Designer.cs 文件中在我背后所做的更改(使用 SVN)时,我的构建再次成功,一切正常。

我看到 Visual Studio 删除了设计器文件中的很多行。

我在网上读到了一些类似的问题,但我找不到一个好的解决方案。

你们中有人在使用 Visual Studio 时遇到过同样的问题吗?可以帮我解决这个问题吗?

更新:我发现 Visual Studio 将此行添加到 Designer.cs:

 protected global::System.Web.UI.WebControls.UpdatePanel UpdatePanel1;

但这应该是:

 protected global::System.Web.UI.UpdatePanel UpdatePanel1;

当我在 Designer.cs 文件中手动进行此更改时,它会起作用。但每次我对 aspx 文件进行更改时,Visual Studio 都会再次创建错误的引用。

Visual Studio isn't behaving normally when I make a change in an aspx file. It makes changes to the designer.cs file. These changes mean that I cannot access any of my controls by their ID in my code behind file.

When I revert the changes (using SVN), that have been made behind my back, in the designer.cs file, my build succeeds again and everything works fine.

I see that Visual Studio deletes a lot of lines in the designer file.

I've read some similar issues on the web but I can't find a good solution for this.

Has anyone of you experienced the same problems with Visual Studio and can help me solving this?

Update: I found that Visual Studio adds this line to the designer.cs:

 protected global::System.Web.UI.WebControls.UpdatePanel UpdatePanel1;

But this should be:

 protected global::System.Web.UI.UpdatePanel UpdatePanel1;

When I make this change manually in the designer.cs file, it works. But every time I make a change to the aspx file, Visual Studio creates again the wrong reference.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

逆蝶 2025-01-14 23:25:33

我有同样的问题。我的解决方法是将定义从设计器文件移动到代码隐藏文件,并将其正确定义为:
Protected WithEvents UpdatePanel1 As Global.System.Web.UI.UpdatePanel

而不是让设计者继续错误地覆盖它,如
Protected WithEvents UpdatePanel1 As Global.System.Web.UI.WebControls.UpdatePanel

我使用 vs2013 vb.net asp web 表单应用程序。

我还看到了将 web.config 文件中的目标框架更改为 4.0 的建议(对我来说不起作用,我的目标是 4.5,两个目标都遇到问题)

,我还看到了使用 Register 标签的建议,例如:
<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web"%>
在页面顶部。这确实解决了我测试时抛出的“错误”,但是它导致我的所有 asp 标记出现大量“警告”。

im having the same issue. my workaround is moving the definition from the designer file to the code behind file and defining it properly as:
Protected WithEvents UpdatePanel1 As Global.System.Web.UI.UpdatePanel

instead of letting designer keep overwriting it improperly as
Protected WithEvents UpdatePanel1 As Global.System.Web.UI.WebControls.UpdatePanel

im using vs2013 vb.net asp web forms application.

i've also seen suggestions to change the target framework in the web.config file to 4.0 (did not work for me, im targeting 4.5, was getting the problem with both targets)

and i also saw a suggestion to use the Register tag like:
<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web"%>
at the top of the page. this did resolve the 'error' that was being thrown when i tested it, however it caused numerous 'warnings' to appear for all of my asp tags.

找回味觉 2025-01-14 23:25:33

我的办公室在 Visual Studio 2013 中受到此问题的困扰。我们使用以下解决方法:

  1. 右键单击项目并选择属性
  2. 应用程序选项卡上,更改目标框架版本并保存项目。
  3. 重复步骤 1 和 2,将目标框架设置回您想要的框架。
  4. 再次保存 .aspx 文件。

这在 100% 的情况下都有效,但我们发现它弄乱了我们的一些 web.config 设置。

我们现在使用以下解决方法,该解决方法似乎也有效,并且不会对项目配置文件进行任何重大更改:

  1. 右键单击项目并选择卸载项目
  2. 右键单击该项目并选择重新加载项目
  3. 再次保存 .aspx 文件。

My office is plagued by this issue in Visual Studio 2013. We were using the following workaround:

  1. Right-click on the project and select Properties.
  2. On the Application tab, change the Target framework version and save the project.
  3. Repeat steps 1 and 2 to set the target framework back to the one you want.
  4. Save the .aspx file again.

This would work 100% of the time, but we discovered that it messed up some of our web.config settings.

We are now using the following workaround, which also seems to work and does not make any breaking changes to the project config files:

  1. Right-click on the project and select Unload Project.
  2. Right-click on the project and select Reload Project.
  3. Save the .aspx file again.
满天都是小星星 2025-01-14 23:25:33

确保cs文件的类名与designer.cs相同,并检查aspx文件中页面的Inherits属性是否相同。另请检查您的项目中是否有任何类与您的页面类名同名,我也想知道在 aspx 页面中进行任何更新时出现的错误。

Make sure that the class name of the cs file is the same as the designer.cs and check the Inherits attribute of the page in the aspx file is the same. Also check if there is any class in your project with the same name as your page class name, also i would like to know the error that appear when you make any updates in the aspx page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文