【发布时间】:2014-01-17 10:38:19
【问题描述】:
我创建了一个嵌套母版页。父母版页 A 继承自 System.Web.UI.MasterPage。子母版页 B 继承自 A。
然后我创建了一个使用母版页 B 并继承自 System.Web.UI.Page 的网页内容页 C。
从网页内容页面 C 我可以访问两个母版页中的变量和方法。然而问题在于访问父母版页变量和方法。
问题是引发了 NullReferenceException。变量和方法没有被初始化。
什么是可能的解决方案?
public partial class ParentMasterPage : System.Web.UI.MasterPage
{
internal Button btn_Parent
{
get { return btn; }
}
}
public partial class ChildMasterPage : ParentMasterPage
{
internal Button btn_Child
{
get { return btn; }
}
}
public partial class WebContentPage : System.Web.UI.Page
{
protected override void OnInit(EventArgs e)
{
Button tempA = Master.btn_Child; //WORKS
Button tempB = Master.btn_Parent; //NULL REFERENCE EXCEPTION
}
}
【问题讨论】:
-
尝试用源代码提供一个更完整的问题,在哪里抛出错误,...
标签: c# asp.net inheritance master-pages