5

EDIT:

There seems to be a visual (?) bug in visual studio. When I opened my website folder as a website and looked at my Views.ascx.designer.cs it doesn't show that it is associated. However, if I open that same website's solution file then the files are associated and all is well.

Just to be clear, even though it is still showing the below error messages it is working and I believe that it's a bug with opening it as a website instead of as a solution.


On my live site I have an error:

enter image description here

But it should exist because I have it in my Views.ascx.designer.cs:

enter image description here

But in Visual Studio my Views.ascx.designer.cs is not being associated with my View.ascx:

problem!

I tried to drag and drop the .designer file onto View.ascx but it displayed this error message:

enter image description here

It works and looks perfectly fine on my dev server:

enter image description here

I'm not sure how I would go about getting the file to associate itself with the View.ascx or View.ascx.cs files.

  • Can you delete it and let it get regenerated? – Shane Wealti Jun 10 '14 at 15:40
  • Please see http://stackoverflow.com/questions/16161994/manual-editing-of-designer-cs-file – Bit Jun 10 '14 at 15:41
  • @ShaneWealti I'm not certain. just right click delete and then rebuild? –  Jun 10 '14 at 15:41
  • @Bit ? I'm not looking to edit it just have it be associated with my files. –  Jun 10 '14 at 15:43
  • Try deleting the designer file entirely (you could save a backup somewhere if you want), then right-click on your project and select "Convert to Web Application". That should work. Happens to me from time to time. – JW Lim Jun 10 '14 at 15:56
  • @JWLim okay. when I open the parent files as website and navigate through the solution explorer it shows they aren't associated but when I open the solution directly it shows that they are. Any idea why that is? It still doesn't work. –  Jun 10 '14 at 16:16

2 Answers2

9

First step: right-click the files and exclude them, and try including them back in. It may fix itself. If not, you could edit the project directly; you just to add the dependency that the CSPROJ or VBPROJ expects. Here is an example that you need to make sure is in the project XML:

<Compile Include="Views\Main.aspx.designer.vb">
  <DependentUpon>Main.aspx</DependentUpon>
</Compile>
<Compile Include="Views\Main.aspx.vb">
  <DependentUpon>Main.aspx</DependentUpon>
  <SubType>ASPXCodeBehind</SubType>
</Compile>
Brian Mains
  • 50,520
  • 35
  • 148
  • 257
  • that code already exists within csproj. `View.ascx True ASPXCodeBehind View.ascx ` –  Jun 10 '14 at 16:02
  • 1
    Interesting.. sometimes VS does glitch like that, and I've had to delete the file and recreate it. Unfortunately, but that usually works. – Brian Mains Jun 10 '14 at 17:33
  • I've seen this happen to me when on a "website" project. Its easily reproducible. Just create a webform in a new webapplication project, make it work, then try to copy over the aspx+cs files and include it in a new "website" project. I had to add a webform in the new project and copy paste contents across files to make it work – mishal153 Feb 09 '16 at 13:28
  • yeah! I created a COM-visible Class, I added a `class.Designer.vb` file, added `inherits UserControl`, excluded the files and re-included. Now they are linked. (not ASP but VB Winforms). thanks! – Ivan Ferrer Villa Oct 20 '16 at 09:45
0

Have had the same issue while adding form from other project to the pending one , I've excluded both files then added back by adding non-designer file 1st and .Designer.cs was then added in the right place automatically from the same catalogue as .cs file (VS2012).

Pacho
  • 36
  • 2