I have a mediocre skill level with VS and C#. I'm attempting to add a .ascx file with codebehind to an existing project in its user controls.
Right-clicking UserControls -> Add -> New Item and searching "web user control" returns "No items found."
Copy-pasting an existing .ascx file (there are more than a dozen) successfully creates the new .ascx file, but there's no .ascx.cs or .ascx.designer.cs files attached and no apparent way to add them.
More information
Copying "MyUserControl.ascx" was indeed copying the codebehind files, but they were copied under the original "MyUserControl.ascx" file as "MyUserControl - Copy.ascx.cs" and ""MyUserControl - Copy.ascx.designer.cs". VS does not allow these files to be renamed or moved.
So, I removed these files from the project, changed their names in file explorer, added them back to the project and updated the code as I needed.
However, they don't appear nested, but on the same level as the .ascx files.
Also tried
Created a blank web app and could add it there, so it's something project-specific.
Tried adding the file as existing after copying in file explorer, with the intent to generate the code behind files - there's no Convert to Web Application option, even when selecting the solution directly and even under the project menu in VS2015 for my project, as suggested by How do you force Visual Studio to regenerate the .designer files for aspx/ascx files?
Now that I've posted a bounty...
Once the items (.ascx, .ascx.cs, and .ascx.designer.cs files) have been added to the project and their content updated to reflect desired changes (Codebehind attribute, class names, etc), simply edit your .projitems file for the project (I used notepad++ for this, not sure if it matters).
You'll find two lines that look something like this - search your file names to find easily:
<Compile Include="$(MSBuildThisFileDirectory)MyPath\UserControls\MyUserControl.ascx.designer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)MyPath\UserControls\MyUserControl.ascx.cs" />
If you have other similar files you'll see that they have a dependent upon node. Adding this node and reloading in VS will get you what you need:
<Compile Include="$(MSBuildThisFileDirectory)MyPath\UserControls\MyUserControl.ascx.cs" >
<SubType>ASPXCodeBehind</SubType>
<DependentUpon>MyUserControl.ascx</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)MyPath\UserControls\MyUserControl.ascx.designer.cs" >
<DependentUpon>MyUserControl.ascx</DependentUpon>
</Compile>