Visual Studio Not Connecting Designer to Code Behind

后端 未结 3 1470
甜味超标
甜味超标 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.

提交回复
热议问题