Tuesday, September 17, 2013

Prefer Using Nested Master Pages Over Separate Master Pages

Most of the websites I've worked on have had an overarching site design with various sections of the site that differ slightly from one another. I've worked on an eCommerce site that had a common layout among all pages - a menu at the top, information about the user and their cart in the upper right corner, legalese at the bottom, section-specific links on the left, and so on - but had minor customizations for the various sections. There were a total of four logical sections: general, non-product-specific pages; general products; logoed merchandise; and order fulfillment pages. The background image used at the top of the page differed among the four sections, and there were different links and slight layout differences in the upper right corner. One approach to managing these differences would be to have four master pages in the project, one for each section. The problem with this approach is that it involves a lot of repeated markup and code, as more than 90% of the site design and layout markup between the sections was identical. As a result, any changes to the overarching design would require modifying the markup in all four master pages. A better approach is to use nested master pages. Much like how an ASP.NET page can have a master page, a master page may also be assigned a master page. Such master pages are said to be nested. With nested master pages you could define a "root" master page that defines the markup and layout that is common to all sections and then create a nested master page for each of the four sections. The content pages in each section would then use the appropriate nested master page. The net benefit of this approach is that the overarching site design markup is consolidated into one "root" master page and the nested master pages contain only the variations among the sections. This makes it much easier to modify the site-wide design and have those changes instantaneously applied to all sections. For more information on using nested master pages, check out Scott Guthrie's blog entry, Visual Studio 2008 Nested Master Page Support. Also reference the tutorial Nested Master Pages. Conclusion Master pages offer ASP.NET page developers an easy way to define a site-wide design and to have it apply to all content pages. All ASP.NET websites should include a master page and that master page should be the first thing added to the project. This article dispensed some master pages advice along with some tips and tricks. If you have additional advice or tips regarding master pages, please share them with your fellow readers by sending them to me. I'll happily add such recommendations to this article. Happy Programming!
http://www.4guysfromrolla.com/articles/062409-1.aspx

No comments:

MS in Computer Science with paid training in USA company