Why do you need master pages and how it can improve the maintenance of your website
Introduction
They normally will copy and paste this tag on all their pages.
This technique worked, but it also raised some issue as the include files in Old Classic ASP file. This is because User Control actually will be rendered the same as include files in Classic ASP.
In ASP.NET 2.0, Master pages has been introduced and this has make all the developers life easy. You can design and see the master pages visually in your Visual Studio 2005.
Why Do You need Master Pages
Most Websites today have common elements used throughout the entire application or on majority of the pages within the applications.
For instance if you look on WorldOfASP.NET website (http://www.worldofasp.net), you can see that the header and footer is being repeated across all the pages in entire website.
Nah, those repeated elements can be stored in the Master Pages. This will save you lots of times to copy and paste the code on all the pages. And imagine if you want to edit the header on footer, then you only need to edit on one single place rather than have to find and replace across all your files.
How to Use Master Pages
To create Master Page, it will be very easy and simple in Visual Studio 2005.
Right Click on your Project and Choose Add New Items --> Choose MasterPage as VS Template
Give the MasterPage a name e.g MasterPage.master.
After you added the Master Page, you will see the directive on top of the page just like below.
<%@ MASTER LANGUAGE="C#" AUTOEVENTWIREUP="true" CODEFILE="MasterPage.master.cs" INHERITS="MasterPage" %>
As you can see that the masterpage contain Master directive while normal Page file will have Page directives. The MasterPage behaves just like normal Aspx page, where you can add code behind, Page_Load Event and etc.
In the Master Page, there is also a piece of code like this
<ASP:CONTENTPLACEHOLDER ID="ContentPlaceHolder1" RUNAT="server">
Web Form
and check the Select Master Page option. You will then be given choice to add Master Page. Choose MasterPage1.Master as the MasterPage.
Your Page file should contain the code like this<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">