[英]Testing to see if ContentPlaceHolder content has been overridden by a child page?
I'm currently migrating a .net 1.1 application to .net 3.5. 我目前正在将.net 1.1应用程序迁移到.net 3.5。
The .net 1.1 application has a number of number of page + usercontrol's that I would like migrated to masterpages. .net 1.1应用程序具有许多我希望迁移到母版页的页面+用户控件。
My issue is trying to test progmatically to see if the masterpage's contentplaceholders content has been overridden by a child page. 我的问题是尝试进行编程测试,以查看母版页的contentplaceholders内容是否已被子页覆盖。
Thanks in advance. 提前致谢。
A page can communicate with the master page but not vice versa since the content in the contentplaceholder does not belong to the master page. 页面可以与母版页通信,反之亦然,因为contentplaceholder中的内容不属于母版页。 The quickest way of setting up a page "registering" itself to the master page is to declare a class that inherits from the .NET MasterPage and expose communication functionality in that class. 设置页面自身“注册”到母版页的最快方法是声明一个从.NET MasterPage继承的类,并在该类中公开通信功能。
public abstract class MyMaster : System.Web.UI.MasterPage { public MyMaster() { } 公共抽象类MyMaster:System.Web.UI.MasterPage {public MyMaster(){}
public abstract void TellMeSomethingAboutTheContent(SomeArgs args);
} }
Then in your page that uses the master you can do something like: 然后,在使用母版的页面中,您可以执行以下操作:
protected void Page_Load(object sender, EventArgs e)
{
MyMaster master = Page.Master as MyMaster;
if (master == null)
return;
master.TellMeSomethingAboutTheContent(args);
}
Assuming of course that you have a SomeArgs class that contains the data you want the master page to know about. 当然,假设您有SomeArgs类,其中包含希望母版页了解的数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.