简体   繁体   中英

Visual Studio Not Connecting Designer to Code Behind

I started using VisualStudio 2013 last week, and have loved it. But I was primarily coding controllers and 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.

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.

Has anybody else had this issue or found a work around in the past with another version of Visual Studio?

It happens sometimes when ASPX and designer are out of sync.

Sometime just saving the ASPX file Ctrl + S solves the problem.

The worst case you can delete the individual xxx.designer.cs, and recreate it by using Convert to Web Application

Visual Studio 2012

在此输入图像描述

Updated for Visual Studio 2013

In VS 2013, Convert to Web Application is moved under 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. 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. For a Web APPLICATION - DO NOT open it by opening VS first and then clicking File...Open...Web Site...

Apparently, when you do this, the VS environment believes you are working on a WEB SITE project instead of a WEB APPLICATION project. 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".

Does that mean that a Page Directive in Web Site uses the keyword CodeFile while the Web Application uses the keyword CodeBehind?

Don't know....I haven't created a "Web Site" from VS 2013. Based on my experience, I think so. 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...? 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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