What is Master Page in ASP.Net 2.0?

Master pages are a new feature introduced in ASP.NET 2.0 to help you reduce development time for Web applications by defining a single location to maintain a consistent look and feel in a site. Master pages allow you to design a template that can be used to generate a common layout for many pages in the application. The primary goal of master pages is to avoid creating each page from scratch and having to repeat the layout code. Another benefit of using master pages is that, if you want to change the layout of the pages in the application, you only have to update the master page rather than each individual page. This feature is somewhat similar to the Windows Form technique of Visual Inheritance, which was available with the original version of the .NET Framework and is used for desktop application development.

A master page looks like any ordinary ASP.NET Web page except for the extension (.master instead of .aspx) and some special controls and header fields. Master pages must contain one or more <asp:ContentPlaceHolder> controls. These controls represent areas of replaceable content. Basically, anything that is not in a ContentPlaceHolder will appear on any page that uses the master page.

Although master pages and frames serve a similar purpose, master pages offer much more functionality. Unlike with frames, using master pages allow you to:

Bookmark a page and recall all the information on the specific page, not just the default frame page. A master page isn't really a frame. It's a single page that contains collated content from the master page and the content page that builds on the master. Therefore it looks and acts like a single Web page rather than a frame.
Work by means of controls and tags rather than HTML. Thanks to Visual Studio, you don't have to worry about opening and closing frame tags or modifying countless html attributes to ensure that each frame displays in the correct fashion. You can simply create the place holder and modify its properties through Visual Studio.
Leverage Visual Studio 2005 code creation to visually design the layout, manage the frames and provide all of the plumbing to link the content pages into the master page. You can add new content without having to worry that the overall HTML layout of the page will be affected.

No comments: