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

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

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

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

提前致谢。

有帮助吗?

解决方案

页面可以与母版页通信,但反之则不然,因为 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 类,其中包含您希望母版页了解的数据。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top