3

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?

jamesbar2
  • 614
  • 1
  • 9
  • 20
  • Does it start working if you (temporarily) uninstall ReSharper? If so, you know that's your culprit, and that they probably aren't officially supporting it yet. – qJake Nov 18 '13 at 18:16
  • I could try, they released it saying it was designed for 2013 in mind. I'll give it a go though. – jamesbar2 Nov 18 '13 at 18:19
  • This might also be a duplicate of this question, check there for possible solutions: http://stackoverflow.com/questions/45325/how-do-you-force-visual-studio-to-regenerate-the-designer-files-for-aspx-ascx-f – qJake Nov 18 '13 at 18:30
  • @SpikeX, this is the same question; however, that solution doesn't work in this context. I've had this happen many times in VisualStudio, but it's normally always fixable by doing exactly the solution in that question. This time, it's not for some reason, it wouldn't have concerned me if it wasn't ongoing. But, it seems to be the case regardless. – jamesbar2 Nov 18 '13 at 20:11
  • @SpikeX also he's using VS 2008, I'm using VS 2013. – jamesbar2 Nov 18 '13 at 20:15

3 Answers3

3

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

Win
  • 61,100
  • 13
  • 102
  • 181
  • 2
    Uh, no ... choosing that option will convert a **web site** to a **web application** project, which, depending on the size of the project, can have unintended side effects (the developer may not want a web application). This is not what you would use to fix the problem. See: http://msdn.microsoft.com/en-us/library/aa983476.ASPX – qJake Nov 18 '13 at 18:28
  • @SpikeX **Right click on an individual file will create the designer.cs for the selected file only, because your application is already web application.** – Win Nov 18 '13 at 18:29
  • 1
    Well that's a terrible design choice by the VS team, then, the verbage of that option should be changed to make more sense. – qJake Nov 18 '13 at 18:33
  • @SpikeX **Please try it by yourself before downvoting and writing a comment.** – Win Nov 18 '13 at 18:34
  • 1
    Spike, I forgot about this feature; however, it's been removed in VS 2013. Otherwise, I think you're correct that would have worked. =\ – jamesbar2 Nov 18 '13 at 18:41
  • @jamesbar2 It also appends in VS2010 and VS2012. Inside source view, I normally use Ctrl+A, Ctrl+K, Ctrl+F (selected all mark up and format selection); it recreates controls inside designer 99% off the time. – Win Nov 18 '13 at 18:54
0

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.

LukeP
  • 10,422
  • 6
  • 29
  • 48
Patty
  • 11
  • I was rebuilding an old WEB and hit this issue. The CodeFile/CodeBehind save my day! – fcm May 05 '20 at 12:09
0

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.

Laura White
  • 188
  • 2
  • 9
craigvl
  • 280
  • 2
  • 9