您好我一直坚持这种情况已经有一段时间了吗?在这里寻求帮助?
我已经定义了嵌套母版页(1个默认用于WebApp和其他自定义母版页引用默认版本)
以下是使用我的自定义母版页的内容页面(例如content.aspx)中的代码snipet
在aspx源代码中我已经包含了:%@ MasterType VirtualPath="~/NestedMasterPage1.master" %>
并在代码后面文件即。 custom.aspx.cs(这就是问题所在):
ContentPlaceHolder masterContentPlaceHolder = (ContentPlaceHolder)Page.Master.Master.FindControl("MainContent"); //works well
ContentPlaceHolder nestedContentPlaceHolderHeading = (ContentPlaceHolder)masterContentPlaceHolder.FindControl("NestedMasterHeading"); //works well
Label NewsHeadLines = (Label)nestedContentPlaceHolderHeading.FindControl("lblSubSectionHeader"); //returns null?? The Control ID is all checked and is the same in the Nested Master Page.
**NewsHeadLines.Text = "Testing";** //System.NullReferenceException:
对象引用未设置为对象的实例。
是否发生这种情况是因为我在HTML表格,行和列中嵌套了我的Control(此处为标签)?请指教?我仔细检查了控件名称或ID。