是否可以从另一个用户控件继承一个用户控件?
我想实现的是一个用户控制从另一个用户控制继承。所以,我有一个baseusercontrol.ascx,它只有文本“Stuff”。然后我有另一个用户控件childusercontrol.ascx继承自baseusercontrol.ascx。如果我不在childusercontrol.ascx中做任何更改,我希望baseusercontrol.ascx中的文本显示为“Stuff”。
而且我应该能够在派生类中扩展基本用户控件的功能。
我还尝试过像this这样的方法,但在我的情况下不够用。
现在我的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.
有什么线索吗?
NullReferenceException
的情况都是相同的。请参阅“.NET中的NullReferenceException是什么?”获取一些提示。 - John Saunders