Visual Studio Not Connecting Designer to Code Behind

后端 未结 3 1469
甜味超标
甜味超标 2021-01-21 00:33

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 W

相关标签:
3条回答
  • 2021-01-21 01:20

    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.

    0 讨论(0)
  • 2021-01-21 01:24

    For me I just needed to right click on the solution and select "Unload Project" then just right click and select "Reload Project", this then connected the code behind file.

    0 讨论(0)
  • 2021-01-21 01:26

    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

    enter image description here

    Updated for Visual Studio 2013

    In VS 2013, Convert to Web Application is moved under Project.

    enter image description here

    0 讨论(0)
提交回复
热议问题