Welcome To My Blog

This blog contains posts that may benefit ordinary visitors or programmers (particularly .NET programmer).
To view posts related to particular subjects, click the link under Labels.

Tuesday, September 16, 2008

Using MasterPage Template In ASP.Net 2005 Application

Introduction

A Master Page in Visual Studio 2005 is just like a template. You can place banners, menus, images and etc on the master page. You can also include codes (functions) on the master page. You can include more than one master page in any asp.net 2005 web application.

Once you have the master page, you can generate the content page (aspx page) which is linked to the master page. This way, you can have several aspx pages (content pages) with a consistent look. In other words, all content pages generated using a master page, will have the same appearance as the master page. For example, if you have placed a banner at the top and navigation menu on the left side of the master page, all content pages will also have the banner at the top and menu on the left side.

How To Add Master Page To ASP.Net Project?
Adding a master page to an ASP.NET project is very easy. You just need to do the following steps:
  1. Right-click on the project name in the Solution Explorer window.
  2. Select Add New Item... from the pop up menu.
  3. Select Master Page from the Add New Item dialog box. If necessary, change the name and the language for the master page. Then click the Add button. You will see a master page is displayed either in the Source or Design view.
  4. Design you master page. For example, you can add an HTML table on the master page. After that, you can arrange the the ContentPlaceHolder control, images, buttons and other controls nicely within the HTML table. You may look at the image below for an example.

How To Add Content Page (aspx page) Using A Master Page?
To add a content page to your asp.net project using a particular master page is relatively easy. All you need to do are:
  1. Open the particular master page that you want to use to generate the master page.
  2. Right-click anywhere within the Design or Source view window and select Add Content Page from the pop up menu that appears.
  3. Notice the asp.net content control in the generated aspx page. This is where you place your content such as text, iframe, images and etc for your content page.
Remember that we use master page to generate a consistent aspx page. Though you cannot set a master page as the start page of your website, you still need to include it in your asp.net web site. This is because the page that is generated using the master page has a link to the master page.

No comments: