---
title: Creating master pages for ASPX templates
related:
  - https://docs.kentico.com/k9/developing-websites/developing-websites-using-aspx-templates/creating-aspx-page-templates.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

You can use standard ASP.NET [master pages](http://msdn.microsoft.com/en-us/library/wtxbf3hh%28v=vs.100%29.aspx) together with ASPX page templates. This is a powerful concept that allows you to share content across all pages without having to add it separately to every page template. For example, you can create master pages containing header and footer sections with a logo, navigation menu, search box etc.

- Define master pages in files with the **.master** extension.
- You can assign one master page to every ASPX page.
- Master pages must always contain one or more **ContentPlaceHolder** controls:

  ```html

  <asp:ContentPlaceHolder ID="plcMain" runat="server"></asp:ContentPlaceHolder>

  ```

  > **Info:** The **ContentPlaceHolder** control specifies where child pages display their content inside the master page.

> **Tip:** **Tip**: It is recommended to store master pages in the **CMSTemplates** folder together with your ASPX page template files. This allows the system to export master pages along with your website when you [deploy](https://docs.kentico.com/k9/deploying-websites.md) it to another instance of Kentico.

## Preparing master pages for ASPX templates

The following code sample shows the markup of a basic master page.

> **Note:** **Important**
>
> - If you installed the Kentico project as a web application, you need to rename the **CodeFile** attribute on the first line to **Codebehind** for the code example to be functional.
> - The **CodeFile/Codebehind** attribute's value must match the name of the master page's code behind file.
> - Set the value of the _Inherits_ attribute according to the location and name of the master page file.

```html

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Custom.master.cs" Inherits="CMSTemplates_CorporateSite_Custom" %>

<%=DocType%>

<html xmlns="http://www.w3.org/1999/xhtml" <%=XmlNamespace%>>
<head id="Head1" runat="server">
    <title id="Title1" runat="server">My site</title>
    <asp:literal runat="server" id="ltlTags" enableviewstate="false" />
</head>

<body class="<%=BodyClass%>" <%=BodyParameters%>>
    <form id="form1" runat="server">
        <asp:PlaceHolder runat="server" ID="plcManagers">
            <ajaxToolkit:ToolkitScriptManager ID="manScript" runat="server" EnableViewState="false" ScriptMode="Release" />
            <cms:CMSPortalManager ID="CMSPortalManager1" runat="server" EnableViewState="false" />
        </asp:PlaceHolder>

        <cms:CMSListMenu ID="CMSListMenu1" runat="server" />

        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        </asp:ContentPlaceHolder>
    </form>
</body>
</html>

```

All ASPX page templates require the following manager controls, so it is a good practice to add them onto your website's master page:

| Control name                     | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ajaxToolkit:ToolkitScriptManager | Allows pages to use AJAX components. If required, the **CMSPortalManager** automatically loads the _ToolkitScriptManager_, but adding the control directly reduces overhead.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| CMSPortalManager                 | Ensures the transferring of content between the database and editable regions. Also provides the management functionality needed for [portal engine zones](https://docs.kentico.com/k9/developing-websites/developing-websites-using-aspx-templates/adding-portal-engine-functionality-to-aspx-page-templates.md).<br>The CMSPortalManager must be placed inside a standard [PlaceHolder](http://msdn.microsoft.com/en-us/library/cc295504.aspx) control.**Note:** **Note**: If your master page contains the **CMSPageManager** control, remove it and add the **CMSPortalManager** instead. The _CMSPageManager_ is an older equivalent, which is obsolete and only available for the purposes of backwards compatibility. |

> **Info:** The [CMSListMenu](https://docs.kentico.com/k9/references/kentico-controls/cms-controls/cms-controls-navigation/cmslistmenu.md) control is one of the options that you can use to generate a menu for [website navigation](https://docs.kentico.com/k9/developing-websites/loading-and-displaying-data-on-websites/building-website-navigation.md).

### Writing the master page code behind

You need to modify the code behind file of your master pages according to the following steps:

1. Add a reference to the **CMS.UIControls** namespace:

   ```csharp

   using CMS.UIControls;

   ```
2. Change the class definition to match the following (the name of the class may be different):

   ```csharp

   public partial class CMSTemplates_CorporateSite_Custom : TemplateMasterPage

   ```

   > **Warning:** Master pages of ASPX templates must always inherit from the **TemplateMasterPage** class.
3. Add the following code into the master page's code behind class:

   > **Note:** Adjust the value of the **PageManager** property according to the ID of the _CMSPortalManager_ control placed on the master page.

   ```csharp

   protected override void CreateChildControls()
   {
       base.CreateChildControls();
       PageManager = CMSPortalManager1;
   }

   protected override void OnPreRender(EventArgs e)
   {
       base.OnPreRender(e);
       this.ltlTags.Text = this.HeaderTags;
   }

   ```

This code ensures that ASPX templates using the given master page support all required functionality.

Now, you can use the new master page to [create ASPX page templates](https://docs.kentico.com/k9/developing-websites/developing-websites-using-aspx-templates/creating-aspx-page-templates.md).
