ASP.NET master pages are a powerful feature which allows developers to create template-like pages which contain 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 do not reiterate the elements already placed on the master page. Instead, they 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.
An ASP.NET master page consist of 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.
Creating a master page in Visual Studio or Visual Web Developer is dead easy. 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 pages are a web developer’s dream: they offer 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.
Some of you 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.
The writer’s company runs ASP.NET training classes in London and throughout the UK.
Tags: .net, asp.net training, computers, information technology, internet, Microsoft, web design, web development









No Comments, Comment or Ping
Reply to “The Power Of Master Pages in Microsoft ASP.NET”
You must be logged in to post a comment.