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/CorporateSiteASPX 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.. The default master page used by the sample Corporate Site ASPX is in the CMSTemplates/CorporateSiteASPX 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 ASPX when following this tutorial for the controls in this guide) and go to Development -> Page templates. Select the Corporate Site ASPX folder, click New template and enter some 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/CorporateSiteASPX folder.
Click Save.
9. Now switch to the Sites tab, assign the page template to the websites where you wish 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 some Page name and select the Use page template option. Select the page template created in the previous steps and click 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.
Page url: http://devnet.kentico.com/docs/5_5r2/controls/index.html?using_aspx_page_templates.htm