简体   繁体   English

Visual Studio未将Designer连接到代码背后

[英]Visual Studio Not Connecting Designer to Code Behind

I started using VisualStudio 2013 last week, and have loved it. 我上周开始使用VisualStudio 2013,并且喜欢它。 But I was primarily coding controllers and JavaScript. 但我主要编码控制器和JavaScript。 However, when I add a control to a Webform inside of a Web Project, it doesn't generate the code inside the .designer.cs file. 但是,当我在Web项目内部向Webform添加控件时,它不会在.designer.cs文件中生成代码。

I can open the file up and add it manually, which is fine for now; 我可以打开文件并手动添加它,现在这很好; but, will get very frustrating in the future. 但是,将来会变得非常沮丧。

For reference, I'm also using Resharper 8, and ASP.NET 4.5. 作为参考,我也使用Resharper 8和ASP.NET 4.5。

Has anybody else had this issue or found a work around in the past with another version of Visual Studio? 有没有其他人有这个问题,或者在过去使用另一个版本的Visual Studio找到了解决方法?

It happens sometimes when ASPX and designer are out of sync. ASPX设计师不同步时,有时会发生这种情况。

Sometime just saving the ASPX file Ctrl + S solves the problem. 有时只保存ASPX文件Ctrl + S解决了这个问题。

The worst case you can delete the individual xxx.designer.cs, and recreate it by using Convert to Web Application 最糟糕的情况是,您可以删除单个xxx.designer.cs,并使用转换为Web应用程序重新创建它

Visual Studio 2012 Visual Studio 2012

在此输入图像描述

Updated for Visual Studio 2013 针对Visual Studio 2013进行了更新

In VS 2013, Convert to Web Application is moved under Project. 在VS 2013中, 转换为Web应用程序Project下移动

在此输入图像描述

对我来说,我只需要右键单击解决方案并选择“卸载项目”,然后右键单击并选择“重新加载项目”,然后连接代码隐藏文件。

I discovered something quite by accident. 我偶然发现了一些东西。

I am new to Visual Studio 2013 but have used all other versions since VS 2003. VS 2013 allows you to create either a Web Site or a Web Application. 我是Visual Studio 2013的新手,但自VS 2003以来已使用过所有其他版本.VS 2013允许您创建网站或Web应用程序。 Once you create your project and save it, it becomes important how you OPEN it! 创建项目并保存后,打开项目变得非常重要!

If you create a Web Application, the best way to open it to work on it is to double click the Solution (or project) file. 如果您创建Web应用程序,打开它来处理它的最佳方法是双击解决方案(或项目)文件。 For a Web APPLICATION - DO NOT open it by opening VS first and then clicking File...Open...Web Site... 对于Web应用程序 - 请不要先打开VS然后单击文件...打开...网站...打开它

Apparently, when you do this, the VS environment believes you are working on a WEB SITE project instead of a WEB APPLICATION project. 显然,当您执行此操作时,VS环境认为您正在处理WEB SITE项目而不是WEB APPLICATION项目。 I did this very thing and lost the connection between my controls and the code behind. 我做了这件事,失去了我的控件和后面的代码之间的联系。 I discovered that if I open a Web Application file by opening it as a Web Site....then, I have to change the wording in the Page Directive - change CodeBehind="xxxx.cs" to CodeFile="xxx.cs". 我发现如果我打开Web应用程序文件打开它作为一个网站....然后,我必须更改页面指令中的措辞 - 将CodeBehind =“xxxx.cs”更改为CodeFile =“xxx.cs” 。

Does that mean that a Page Directive in Web Site uses the keyword CodeFile while the Web Application uses the keyword CodeBehind? 这是否意味着Web应用程序使用关键字CodeBehind时,Web站点中的Page Directive使用关键字CodeFile?

Don't know....I haven't created a "Web Site" from VS 2013. Based on my experience, I think so. 不知道....我还没有从VS 2013创建一个“网站”。根据我的经验,我想是的。 My suggestion. 我的建议。 If you have created a "Web Application" in VS 2013 and all the sudden you lose the connection between your design file (.aspx) and your codebehind file (.cs or .vb)....did you open it using File.....Open....Web Site...? 如果您在VS 2013中创建了“Web应用程序”,并且突然间您丢失了设计文件(.aspx)与代码隐藏文件(.cs或.vb)之间的连接....是否使用File打开它。 ....打开....网站......? If so, close it. 如果是这样,请关闭它。 Then open it up again just by opening your solution (or project) file, not by opening a "web site". 然后只需打开解决方案(或项目)文件再打开它,而不是打开“网站”。

Hope this helps someone, it drove me crazy for half a day before I figured it out. 希望这对某人有所帮助,它让我疯狂了半天才弄明白。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM