Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code behind file not recognizing controls in *.ascx

Tags:

c#

asp.net

ascx

I have a QuestionControl.ascx and a QuestionControl.ascx.cs code behind file I copied to a new project. When I build the project any references in the code behind file to controls declared in the ascx gives me this error:

'QuestionControl' does not contain a definition for 'rdbtnlstQuestion1' and no extension method 'rdbtnlstQuestion1' accepting a first argument of type 'QuestionControl' could be found (are you missing a using directive or an assembly reference?)

This is at the top of my *.ascx:

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

I've 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 a namespace:

public partial class QuestionControl : System.Web.UI.UserControl
{
like image 408
AaronLS Avatar asked May 21 '10 15:05

AaronLS


2 Answers

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.

like image 114
Don H Avatar answered Oct 17 '22 08:10

Don H


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.

like image 30
Jason Avatar answered Oct 17 '22 08:10

Jason