Add ASP.NET Masterpage Afterwards

When you’ve got some existing ASP.NET pages and you later on want to add a common masterpage, do this:

Master Page

  1. Create a masterpage, e.g. Management.Master.
  2. Add the sub pages’ comon controls to the master.
  3. In the Management.Master, add ContentPlaceHolder items for head and body:
<asp:ContentPlaceHolder ID="CphHead" runat="server" />
<asp:ContentPlaceHolder ID="CphBody" runat="server" />

Sub Page

Do the following in the subpage.aspx:

  1. Add masterpagefile to page level directive:
    <%@ Page ... MasterPageFile="Management.Master"
  2. Remove the <!DOCTYPE>, <html>, <form> and </form>, </html> tags.
  3. Replace the <head> tag by the <asp:Content...> tag respecting the link to the ContentPlaceHolder via ID and ContentPlaceHolderID, like this:
<asp:Content ID="Cont1" ContentPlaceHolderID="CphHead" runat="server">
    // former head content goes here
</asp:Content>
  1. Likewise replace the body tag by the tag:
<asp:Content ID="Cont2" ContentPlaceHolderID="CphBody" runat="server">
    // former body content goes here
</asp:Content>

Sub Page Easy

If you’ve got nothing than the <title> tag inside of the <head> section, it is a bit easier:

  1. Add masterpagefile and title to page level directive:
    <%@ Page ... MasterPageFile="Management.Master" Title="Subpage"
  2. Remove the <head> section.
  3. Replace the <body> tag by the <asp:Content...> tag respecting the link to the ContentPlaceHolder via ID and ContentPlaceHolderID, like this:
<asp:Content ID="Cont1" ContentPlaceHolderID="CphBody" runat="server">
    // former body content goes here
</asp:Content>

Finish