简体   繁体   English

测试以查看ContentPlaceHolder内容是否已被子页面覆盖?

[英]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内容是否已被子页覆盖。

  1. Is it possible? 可能吗?
  2. Does anyone have samples or references that I could take a look at? 有人有样品或参考资料供我参考吗?

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.

相关问题 内容页面找不到ContentPlaceHolder'ContentPlaceHolder1' - Content page cannot find ContentPlaceHolder 'ContentPlaceHolder1' 子页面的正文中的图像ContentPlaceHolder - Image in body of Child page ContentPlaceHolder 母版页需要知道当前内容页是否未使用ContentPlaceHolder - Master page needs to know if a ContentPlaceHolder hasn't been used by current content page 使用子内容页面在MasterPage ContentPlaceHolder中隐藏子MasterPage上的面板 - Hide Panel on Child MasterPage Inside MasterPage ContentPlaceHolder using Child Content Page 将Page.Title设置为asp:contentplaceholder的一部分后,对其进行引用 - Referencing Page.Title after it has been set as part of a asp:contentplaceholder 母版页中contentplaceholder之外的更新面板导致回发到内容页 - An updatepanel outside of contentplaceholder in master page causes post back to content page 删除子页面中ContentPlaceHolder的所有当前应用样式? - Remove all currently applied styles for a ContentPlaceHolder in child page? 我们可以在子母版页中的contentplaceholder中找到div标签 - can we palce div tags inside contentplaceholder in child master page 如何判断是否已在MVC中填充了asp:ContentPlaceHolder? - How can I tell whether an asp:ContentPlaceHolder has been populated in MVC? 访问母版页上的contentplaceholder - Accessing a contentplaceholder on a master page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM