ASP.NET 2.0: Dynamically assigning a master page



  • I hope one of you wtf'less code gurus can help me with a tricky problem:

    I need to, based on certain parameters, dynamically change the masterPageFile of a page - this is all well and nice; I inherit my page from a BasePage that overrides the PreInit method to change the MasterPageFile; however the problem is that I do not know the ContentPlaceHolderID's that the content page references beforehand, and so I cannot avoid the odd exception..

    I'd prefer to get around this by reading which placeholdercontrolsId's the content page references and then either dynamically creating those in the master page or even by redirecting to an existing masterpage - or possibly by modifying the id's in the content page itself - any ideas?

    I would prefer to do this without reading the aspx-file and parsing its contents and preferably without reflection too. And definitely without pre-determining valid contentplaceholderId's.

     


Log in to reply