是否可以从另一个用户控件继承用户控件?
我想要实现的是从另一个用户控件继承的用户控件。所以我有baseusercontrol.ascx,它只有文本“Stuff”。然后我有另一个用户控件,childusercontrol.ascx 继承了 baseusercontrol.ascx。如果我不更改 childusercontrol.ascx 中的任何内容,我希望 baseusercontrol.ascx 文本显示“Stuff”。
而且我应该能够扩展派生的基本用户控制功能。
我也尝试过类似的方法,但在我的情况下还不够。
现在我的 childusercontrol.ascx 看起来在下面
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="childusercontrol.ascx.cs" Inherits="test_childusercontrol" %>
<%@ Register src="baseusercontrol.ascx" tagname="baseusercontrol" tagprefix="uc1" %>
childusercontrol.ascx.cs 如下
public partial class test_childusercontrol : baseusercontrol
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
当我浏览此页面时,我收到错误消息
Object reference not set to an instance of an object.
Description : An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details : System.NullReferenceException: Object reference not set to an instance of an object.
有什么线索吗?