views:

200

answers:

2

The basic idea of a masterpage is simple -- you have a block of content that you want to 'inject' into a location in a master page.

Its very easy to figure this out without even reading the documentation about masterpages (which I admit to not having read!).

What i want to do is pass 'properties' to a master page from its child. For instance I may have a main content panel for which i want to set the padding in pixels in the child page. There may be other simple 'primitive types' that I want available to the master page to render its children. I want to avoid messing with style sheets as much as possible - or I'll end up with a tonne of similarly named items.

Is there a prefered way to do this?

+1  A: 

Yes, but the other way round.

If you set the MasterPageType property of your content page you can access all public properties of the master page using the Master.PropertyName syntax.

So your child page can get and set property values of the master page.

Rune Grimstad
+2  A: 

In your master page create some type of hook (a property or method) that allows some piece of code to manipulate the master page in whatever way you want. Then on the individual pages do something like this:

YourMasterPageType masterPage = (YourMasterPageType)Page.Master;
masterPage.YourHook();

Whatever you do, do NOT do things the other way around (creating special cases within the master page that search the page for some magic value). You want to provide an interface to manipulate the master page, otherwise you'll end up with very messy code eventually.

Dan Herbert
the interface tip was priceless !!
Perpetualcoder