Using the master pages |
Top Previous Next |
Kentico CMS allows you to use standard ASP.NET 2.0 master pages together with ASPX page templates. This is a very powerful concept, that allows you to share the same site header and footer with logo, main menu, search box, etc. over all pages without having to create these sections on each page template again and again.
The master pages are defined in files with extension .master. You can assign a single master page to each ASPX page. The master page must always contain the ContentPlaceHolder control like this:
<asp:ContentPlaceHolder ID="plcMain" runat="server">
The ContentPlaceHolder control specifies where the content of page templates should be loaded. So the master page typically contains the main logo and navigation and the content is displayed by ASPX pages loaded into the master page.
The following code sample defines a very simple master page:
The CMSPageManager control ensures loading of the content from the database into the editable regions. The CMSMenu control displays a drop-down menu. The ContentPlaceHolder control defines where the content of sub-pages should be loaded.
In case that you are planning to use AJAX components on your site, you need to add the ScriptManager control after the CMSPageManager control.
We use CMSMenu and CMSPageManager controls on the page template, so we need to add the CMS.UIControls namespace in code behind:
[C#]
[VB.NET]
The master page must be inherited from the TemplateMasterPage, so the class definition must look like this:
[C#]
[VB.NET]
And you also need do put the following code to the master page code-behind class:
[C#]
[VB.NET]
You should store master pages in the CMSTemplates folder together with page templates, so that they are exported with your web site. |