Dot.Nut

Friday, January 20, 2006

MasterPages in .net 2.0

When doing html for the websites, it is common to have a constant look and feel across pages, like header, menubar and footer. Having to make a change on a layout across all pages wasted time and it was common for developers to create include files for these pages. So the developer only had to update the include file to reflect the change across all pages. But include files were messy, non-standard and not supported in many visual IDEs.

MasterPages in .net 2.0 serves this issue well. It is essentially a control with contentplaceholder regions that "contain" other content pages, which could specify a MasterPageFile to dervive its container html from. the content page simply specify a master file to use, and use a content control with a matching ContentPlaceHolder ID as the master file's, then its all set to go. VS2005 supports masterpages in designer view out-of-the-box, but only for non-nested master pages.

Things to note:
  • MasterPages can nest, but designer view in VS2005 doesnt support
  • A Content control in a content page must have a matching ContentPlaceHolder ID with one of the ContentPlaceHolders the specified MasterPageFile
  • Content Page_Load fires 1st, then Master Page_Load > Content Control Events > Master Control Events
  • A Content page can access public properties defined in a master file. Use ((MasterPage)this.master).property or this.master.property if a <%@ MasterType TypeName="MasterPage" %> directive is specified in aspx.

0 Comments:

Post a Comment

<< Home