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

发布于 2024-07-24 23:23:27 字数 230 浏览 4 评论 0原文

我目前正在将 .net 1.1 应用程序迁移到 .net 3.5。

.net 1.1 应用程序有许多页面+用户控件,我希望将其迁移到母版页。

我的问题是尝试以编程方式进行测试,以查看母版页的 contentplaceholders 内容是否已被子页面覆盖。

  1. 是否可以?
  2. 有人有样品或参考资料可供我看一下吗?

提前致谢。

I'm currently migrating a .net 1.1 application to .net 3.5.

The .net 1.1 application has a number of number of page + usercontrol's that I would like migrated to masterpages.

My issue is trying to test progmatically to see if the masterpage's contentplaceholders content has been overridden by a child page.

  1. Is it possible?
  2. Does anyone have samples or references that I could take a look at?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

画▽骨i 2024-07-31 23:23:27

页面可以与母版页通信,但反之则不然,因为 contentplaceholder 中的内容不属于母版页。 设置页面将自身“注册”到母版页的最快方法是声明一个继承自 .NET MasterPage 的类,并公开该类中的通信功能。

公共抽象类 MyMaster :System.Web.UI.MasterPage
{
public MyMaster() { }

public abstract void TellMeSomethingAboutTheContent(SomeArgs args);

}

然后,在使用母版页的页面中,您可以执行以下操作:

protected void Page_Load(object sender, EventArgs e) 
{ 
    MyMaster master = Page.Master as MyMaster;


    if (master == null)
        return;


    master.TellMeSomethingAboutTheContent(args);
}

当然,假设您有一个 SomeArgs 类,其中包含您希望母版页了解的数据。

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. 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.

public abstract class 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文