views:

148

answers:

1

Hi all,

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.

A: 

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.

Eric
Thanks.. I'll try that..
Jeremy