A while ago, I wrote a post about handling images in themes. At the end of the post I promised to post a way of dynamically assigning the Master Page of any given Page. Well, as it turns out, its actually quite simple - all you have to do is set the MasterPageFile property of the Page during the PreInit stage of the page lifecycle - for example by overriding the OnPreInit method.
Now obviously whichever master page you supply will have to have a set of ContentPlaceHolder controls with ids that match the Content controls on the page - just like you would normally.
This can be a pretty neat way of dynamically loading a master page that for example sits in the current theme directory, essentially allowing you to not only change style information when you switch theme, but also switch the entire master layout. For example, you could do something like:
protected override void OnPreInit(EventArgs e)
{
this.MasterPageFile = String.Format("~/App_Themes/{0}/Theme.Master", this.Theme);
}
Assuming all themes have a Theme.Master file that contains the Master Page definition.