Feb 09
2010The Power Of Microsoft ASP.NET Master Pages
Filed Under (Computers) by Jake Smith on 09-02-2010
Tagged Under : asp.net training, Computers, information technology, internet, Microsoft, net, web design, Web Development
ASP.NET master pages are powerful template pages containing information that is common to all pages in a site or all pages in one section of a site such as corporate logo, company information, headers, footers and navigation links. Content pages can then be created which are based on the master page(s). Master pages use the file extension “.master” which is automatically protected by the server and cannot therefore be downloaded by clients.
The content pages consist of a reference to the appropriate master page together with the main page content and they use the regular ASP.NET file extension: “.aspx”. When the client requests a content page, the master and content pages are combined on the server and the resulting page sent back to the client.
Master pages contain locked areas, which can only be edited from the master and content areas, which can be filled with unique content each time a content page is created. You can create as many content areas as you need, though the default of one in the head area and one in the body is usually enough.
To create a master page in Visual Studio or Visual Web Developer, choose Add New Item from the Website menu and click on the Master Page icon. As with regular ASP.NET pages, you can choose the coding language and specify whether code will be placed in an external file or embedded in the page itself. To create a content page, choose Add New Item from the Website menu, click on the Web Form icon and activate the option “Select Master Page”. When you click the Add button, a second dialog will appear allowing you to choose a master page.
Master and content pages provide web developers with a great way of controlling the structure and layout of all the pages in a site. In addition, when working on content pages in Visual Studio or Visual Web Developer, the master page elements are displayed in preview mode, so the developer can always see what the final, composite page will look like to the end user. Naturally, however, the master page items cannot be edited from the content page.
Anyone familiar with Dreamweaver may be tempted to make a comparison between Dreamweaver templates and ASP.NET master pages. However, ASP.NET master pages are much more powerful. In Dreamweaver, all of the template markup has to be copied into each page based on a template. If the template is altered, each page based on the template has to be updated and then uploaded to the server. With ASP.NET master pages, the master page elements are automatically combined with the content page element at runtime by the ASP.NET engine. So when a master page is altered, there is no need to manually update the content pages.
Author’s company runs public courses in ASP.NET 3.5 in London and throughout the UK.
