Code behind a file that does not recognize controls in * .ascx

I have QuestionControl.ascx and the QuestionControl.ascx.cs file behind the file that I copied to the new project. When I create a project, any links in the code behind the file to the controls declared in ascx give me this error:

'QuestionControl' does not contain a definition for 'rdbtnlstQuestion1' and there is no extension method 'rdbtnlstQuestion1' accepts the first argument of the type 'QuestionControl' (you don’t see using the directive or assembly link?)

This is at the top of my * .ascx:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="QuestionControl.ascx.cs" Inherits="QuestionControl" %> 

I also tried CodeBehind:

 <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="QuestionControl.ascx.cs" Inherits="QuestionControl" %> 

This is the top of my class in the codebehind file, it is not contained in the namespace:

 public partial class QuestionControl : System.Web.UI.UserControl { 
+7
source share
6 answers

Try deleting the designer file. VS.NET should recreate it for you when you open the ascx file. I had problems like this in the past, when the developer for some reason came out of synchronization, and removing it usually fixes the problem.

+13
source share

Another solution:

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

(maybe the ascx.designer.cs file may be closed when updating for this)

+5
source share

What worked with me was indicated on another SO answer and I cannot find it, so I repeat it here.

Try deleting the "ReflectedSchemas" folder in

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

It worked for me. Sometimes I get "unrecognized" errors and I delete this folder again. Thanks a lot OP. I drove me crazy over the years. Now I do not have "squiggles" in HTML and there are no "red bars" in the code behind (aspx.cs)

+1
source share

I am having problems, for example, creating a dropdown list inside a gridview. I created ddl outside gv until desinger.cs recognized it and then moved the control inside gv ... hope this helps

0
source share

I had the same problem, the code did not recognize the controls on the .aspx page. I am using VS 2012. I right-clicked the project; Click Convert to Web Application and he added all the designer files that were not there before. I rebuilt everything, and now it's good.

0
source share

In VS2017, there is no "Convert to Web Application" option in the context menu of the .ascx file. Instead, you need to select the .ascx file, then click "Project" in the top menu and select "Convert to Web Application" (which is located in the "Project" menu).

0
source share

All Articles