Master-Page-Limitation in ASP.NET 2.0
The concept of Masterpages introduced in ASP.NET “Whidbey” is really fascinating. But it seems to have one major limitation, which appears to make it quite unusable in bigger Web-Applications: There seems to be no functionality, which allows a developer to programmatically change the used Master-Page at runtime.
If you think so, you should read this article: http://msdn.microsoft.com/msdnmag/issues/04/06/ASPNET20MasterPages/default.aspx
After reading this, you'll be able to change the MasterPage at runtime using the new PreInit-Event:
protected override void OnPreInit(EventArgs e)
{
this.MasterPageFile = "OtherTemplate.master";
base.OnPreInit(e);
}
Protected Overrides Sub OnPreInit(ByVal e As EventArgs)
Me.MasterPageFile = "OtherTemplate.master"
MyBase.OnPreInit(e)
End Sub
And after all, the concepts of MasterPages should work. :-)
Thanks to Scott Galloway (http://www.mostlylucid.co.uk) for his hint on this topic.