|
Comments
|
Today's Top SOA Links
ASP.NET Introducing ASP 2.0 Master Pages
Factor out the common page elements in your site
By: Thom Robbins
Sep. 9, 2005 03:00 PM
When the page creates its master property, any public properties are automatically typed and available within the content page. This means that we can directly access our MenuItem property use without having to cast a reference (as shown below). lblMenu.Text = Master.MenuItem The FindControl method is used to locate specific controls on the master page, as shown in Figure 9. By default the controls on a master page aren't directly accessible by content pages, because they are considered protected. However, by using the FindControl method you can locate and set the value of the label control located on the master page as shown in the code example below. It is important to keep in mind that at run time the ContentPlace-Holder control has been merged with content from a Content control. By default, the ContentPlaceHolder control will not contain its default content. Instead, it will contain the text and controls that are defined in the content page. Up to this point we have declared master pages declaratively. It is possible to attach to a master page to a content page dynamically. The merging of the master page and the content page is done during the initialization stage of the page processing. In order to dynamically assign a master page, this has to be done prior to the page initialization. The only place this can be done and not generate an error is during the PreInit stage. This is the earliest event that occurs in an ASP.NET page life cycle. This can be done using the following code: Site Branding with Master Pages Up to this point, we have used the MasterPageFile attribute in the Page directive within content pages to declaratively specify the master. Even though this approach works, it does requires that each page directly add the MasterPageFile attribute. For larger sites, this probably isn't a practical solution. ASP.NET 2.0 provides a page element in the web.config that can automatically enforce this requirement. Essentially, all of the pages in that Web application will automatically use the designated master page. For example, the following web.config file entry specifies that all of the pages in the Web application should use Company.master as the default master page. Specifying a master page within the web.config is merely setting a default. Even when this method is used to specify the name of a default master page, it can still be overridden using the Page-level directive. Any values specified within the Page directive automatically take precedence over the web.config file entry. As the meeting started to wind down I could see a lot of relieved and smiling faces. The developers started talking among themselves as we wandered out into the hall. The lead developer walked with me towards my car with a pleasantly surprised smile on his face. He explained that he was glad to understand the basics of master. Of course, like this article, it's only the beginning and the rest is up to you to discover and implement within your Web sites.
Reader Feedback: Page 1 of 1
Your Feedback
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
||||||||||||||||||||||||||||||