|
||
You can use standard ASP.NET master pages 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.
Master pages are defined 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 as shown here:
<asp:ContentPlaceHolder ID="plcMain" runat="server"></asp:ContentPlaceHolder> |
The ContentPlaceHolder control specifies where child pages display their content inside the master page.
It is recommended to store master pages in the CMSTemplates folder together with the page template files, so that the system can export them along with your website when you deploy it to another instance of Kentico CMS.
The following code sample shows the markup of a basic master page.
|
Important!
If you installed the Kentico CMS 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. This attribute's value needs to 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.
|
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Custom.master.cs" Inherits="CMSTemplates_CorporateSite_Custom" %> |
All ASPX page templates require the following manager controls, so it is a good practice to add them onto your website's master page:
•ajaxToolkit:ToolkitScriptManager - allows pages to use AJAX components. This is required by all pages that contain the CMSPortalManager control.
•CMSPortalManager - ensures the transferring of content between the database and editable regions. It also provides the management functionality needed for portal engine zones. Always place this control after the ToolkitScriptManager control.
|
CMSPageManager control
You may use the CMSPageManager control instead of the CMSPortalManager. This control is an older equivalent available for the purposes of backwards compatibility. It does not support ASPX templates containing portal engine web part or widget zones. |
The CMSMenu control is one of the options that you can use to generate a drop-down menu for website navigation.
You also need to modify the code behind file of the master page:
1. Add a reference to the CMS.UIControls namespace:
[C#]
using CMS.UIControls; |
[VB.NET]
Imports CMS.UIControls |
2. Change the class definition to match the following (the name of the class may be different):
[C#]
public partial class CMSTemplates_CorporateSite_Custom : TemplateMasterPage |
[VB.NET]
Partial Class CMSTemplates_CorporateSite_Custom Inherits TemplateMasterPage |
Master pages must always inherit from the TemplateMasterPage class.
3. Add the following code into the master page's code behind class:
[C#]
protected override void CreateChildControls() |
[VB.NET]
Protected Overrides Sub CreateChildControls() |
Adjust the value of the PageManager property according to the ID of the CMSPortalManager (or CMSPageManager) control placed on the master page.
This code ensures that ASPX templates using the given master page support all required functionality.