我有一些代码,当它执行时,它抛出一个NullReferenceException,说:
你调用的对象是空的.
这是什么意思,我该怎么做才能解决这个错误?
我想创建一个DerivedUserControl.ascx从另一个用户控件派生的用户控件BaseUserControl.ascx.基本用户控件根据System.Web.UI.UserControl需要派生.这些用户控件在不同的文件夹中定义.因为我正在使用Visual Studio 2010网站项目(我无法切换到Web应用程序项目),所以这些用户控件未在命名空间内定义.
我的问题是,当我尝试编译项目时,无法解析派生用户控件的基类(显然是因为编译器不知道.ascx文件定义了基类).有办法解决这个问题吗?
我尝试了所有我能想象到的东西,没有成功.任何帮助将不胜感激.
BaseUserControl.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="BaseUserControl.ascx.cs" Inherits="BaseUserControl" %>
Run Code Online (Sandbox Code Playgroud)
BaseUserControl.ascx.cs
public partial class BaseUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
Run Code Online (Sandbox Code Playgroud)
DerivedUserControl.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="DerivedUserControl.ascx.cs" Inherits="DerivedUserControl" %>
Run Code Online (Sandbox Code Playgroud)
DerivedUserControl.ascx.cs
public partial class DerivedUserControl : BaseUserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
Run Code Online (Sandbox Code Playgroud)
错误
The type or namespace name 'BaseUserControl' could not be found
Run Code Online (Sandbox Code Playgroud)