Understanding Master Pages in ASP.NET 2.0

To let you achieve a consistent look and feel for your website ASP.NET 2.0 has introduced Master Pages.

Below Figure 1 shows a screenshot of this website. Every page on the site has the same consistent look and feel. The only section of any page that changes is the center content that in this screenshot is whitened out.

Figure 1
MasterPages

The current site is built using ASP, though if we decided to migrate the site to ASP.NET 2.0 we could make use of Master Pages to define all the common elements that are standard to all pages. We could create a template i.e. the Master Page that would house the logo, banner, footer and side navigation bars and any other navigation menus.

The Master Page would also let us stipulate an area or region within its template that we use as a content placeholder for each individual page’s content. So for Figure 1 we could define the content placeholder as the whitened out region.

With our Master Page in place we could create an aspx web page that only needs to define its unique content and make a reference to the Master Page, and this content can then plug into specified areas of the Master Page layout i.e. the content placeholder.

For example if we created an aspx file called ‘mypage.aspx’ Figure 2 would be it’s unique content.

Figure 2
ContentPage

With both our Master Page and Content Page defined Figure 3 shows the actual page that is returned to your browser when you request the page ‘mypage.aspx’. You can see that our Content Page has merged with the MasterPage to produce our final page ‘mypage.aspx’.

Figure 3
MasterPage ContentPage

A Master Page allows multiple Content Pages to inherit its layout, which makes it a great place to place all the common layout elements. Another point to note is that if you make a change to the Master Page then all the Content Pages will be updated, so if you decide to change the logo then all the Content Pages would inherit the new logo.

Read more on Master Pages in ASP.NET 2.0

Advertisements



MembersPro

MembersPro PayPal - ASP Membership software

Plug and play ASP membership script that integrates with PayPal to let you charge recurring membership fees.

Get your best asp web hosting provider now and save 25%