Code behind file not recognizing controls in *.ascx

In VS2017 there is no option 'Convert to Web Application' in the context menu of the .ascx file. Instead you need to select to .ascx file then click on 'Project' in the upper menu and select 'Convert to Web Application' (which is all the way down in the Project menu.


Try deleting your designer file. VS.NET should recreate it for you when you open the ascx file. I've had problems like this in the past where the designer gets out-of-sync for some reason, and deleting it usually fixes the problem.


What worked form me was listed on another SO answer and I can't find it so I'm repeating it here.

Try deleting your "ReflectedSchemas" folder in

C:\Users\YOURUSENAME\AppData\Roaming\Microsoft\VisualStudio\15.0_079f391b\ReflectedSchemas

This worked for me. Sometimes I get the "unrecognized" errors, and I delete this folder again. Many thanks to the OP. Been driving me crazy for years. Now I have no "squiggles" in the HTML and no "red bars" in the code behind (aspx.cs)


Another solution is to:

  • open your .ascx page in design view
  • right click anywhere on the page and select Refresh

(.ascx.designer.cs file may need to to be closed while doing refresh for this to work)

Tags:

C#

Asp.Net

Ascx