Kentico CMS 6.0 Controls

Using ASPX page templates

Using ASPX page templates

Previous topic Next topic Mail us feedback on this topic!  

Using ASPX page templates

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

Placing controls on ASPX page templates is one of their most common uses. For additional information about page templates, please refer to Developer's Guide -> Development -> Web development overview -> ASPX page template development.

 

The following is a step-by-step tutorial showing how a new ASPX page template can be created and registered in the system.

 

1. Open your Kentico CMS web project in Visual Studio using File -> Open -> Web Site... in the menu.

 

2. Now right-click the CMSTemplates/CorporateSite folder in the Solution Explorer and select Add New Item.

 

3. Choose to create a new Web Form (.aspx page) and check the Select master page box. Click Add.

 

4. The Select a Master Page dialog appears. Choose a master page file and click OK. You can use the default ASPX master page in the CMSTemplates/CorporateSite folder named root.master.

 

5. Switch to the Source view of the newly created web form. Add the following line under the <%@ Page %> directive:

 

<%@ Register Assembly="CMS.Controls" Namespace="CMS.Controls" TagPrefix="cms" %>

 

You can now add any HTML code inside the <asp:Content> element, including any CMS controls and their definitions.

 

6. Switch to the code behind. You need to add a reference to the CMS.UIControls namespace:

 
[C#]
 

using CMS.UIControls;

 

7. The last step is to modify the class from which the page is inherited. Change the following code:

 
[C#]
 

public partial class CMSTemplates_CorporateSiteAspx_Example : System.Web.UI.Page

 

to this:

 
[C#]
 

public partial class CMSTemplates_CorporateSiteAspx_Example : TemplatePage

 

Now the page can be correctly used as a page template in Kentico CMS.

 

Please keep in mind that the name of the class must be identical to the value of the Inherits attribute of the <%@ Page %> directive on the ASPX page. This is case sensitive.

 

Registering the ASPX page as a page template

 

Now that we have created a new ASPX page, we need to register it in Kentico CMS as a page template so that it can be used.

 

8. Sign in to Site Manager (we recommend doing this on the sample Corporate Site when following this tutorial for the controls in this guide) and go to Development -> Page templates. Select a folder, for example Corporate Site/Examples, click AddTemplate New template and enter a display and code name.

 

Click OK. Now use the Select button to choose the .aspx file created in the previous steps located in the ~/CMSTemplates/CorporateSite folder.

 

Click Save Save.

 

9. Now switch to the Sites tab, assign the page template to the websites where you wish for it to be available using the Add sites button and click OK.

 

Creating a page based on the new page template

 

10. Go to Kentico CMS Desk -> Content. Create a New document of type Page (menu item). Enter a Page name and select the Use existing page template option. Select the page template created in the previous steps and click Save Save to create the page.

 

Now you have a page using an ASPX page template. Any changes made to the source .aspx file will now be automatically reflected by this page.