我在复制到新项目的文件后面有一个QuestionControl.ascx和QuestionControl.ascx.cs代码。当我构建项目时,文件背后代码中对ascx中声明的控件的任何引用都会给我这个错误:



这是我的* .ascx的顶部:

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

我也尝试过CodeBehind:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="QuestionControl.ascx.cs" Inherits="QuestionControl" %>

这是代码隐藏文件中类的顶部,它不包含在 namespace 中:
public partial class QuestionControl : System.Web.UI.UserControl
{

最佳答案

尝试删除您的设计器文件。打开ascx文件时,VS.NET应该为您重新创建它。过去,我曾遇到过类似的问题,由于某些原因,设计师会变得不同步,删除它通常可以解决问题。

关于c# - 文件后面的代码无法识别* .ascx中的控件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2883301/

10-11 22:23