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.
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. 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.