I have a project where a basic ASP.NET public web site drills into a private SharePoint web object model and produces most of the content for the public side. One area in particular presents many science projects that go on within the organization. Some folks want different options though as to how their projects are presented on the page–meaning they might want three columns instead of two or a different menu style, etc.

My first thought was that trying to do that and still use the same aspx page would mean having to create all the page controls etc. in code and then add them to the page. Possibly each different layout would have its own method block with all the code to do that. Can you imagine how messy that could get. Then if the pages had any kind of event associations etc. it would get even worse.

Then I considered the possibility of using the nested master page concept. Basically just turn my project.aspx?projID=xx into a masterpage director. So that when the project.aspx page loaded it would check what template was suppose to be associated with the project and then choose that one by assigning the correct master page.

In my Page_PreInit I would need to add code to check the SharePoint project list item based on the projectID querystring value and get the name of the template that was supposed to be associated with that project.
Then do something like the following:

string templateName = “TemplateNameFromSPProjectList”;
this.Page.MasterPageFile = “~/” + templateName + “.master”;

I’ll have to post back the results of taking this approach. If anyone knows of a better way of doing this let me know. And if there are any drawbacks that I don’t see in taking this route of operating mostly within a nested master page for page buildout let me know.

Advertisement