My Web Parts in ASPX Page Temlate

Mateusz Żebrowski asked on April 17, 2014 16:04

My task: create page template with contain web parts developed by me.

Here what I've done: I've developed my own web part as it was described in Kentico Developer Guide. This is very simple one so I can write it's code.

ascx file:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="customWebPart.ascx.cs" Inherits="CMSWebParts_Custom_customWebPart" %>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

cs file:

using CMS.PortalControls;

public partial class CMSWebParts_Custom_customWebPart : CMSAbstractWebPart
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text = (string)this.GetValue("Text");
    }
}

As you can see this web part is only a label and you can edit it's text via web part properties.

After create I've of course registred this web part and add a property "Text".

Next step is quite problematic. I need to create a page template. It's possible to write something like that:

<cms:CMSPagePlaceholder ID="Holder" runat="server">
        <LayoutTemplate> 
            <cms:CMSWebPartZone runat="server" ID="zone" WebParts="custom"/>           
        </LayoutTemplate>
    </cms:CMSPagePlaceholder>

and add my web part via cms desk but it's not the point. I need to put this web part exactly into page template, and it should by editable from cms desk.

Recent Answers


Brenden Kehren answered on April 17, 2014 20:12

Webparts are typically used for Portal development mode and not ASPX development mode. Webparts are collections of controls that publicly expose properties for the end user/content editor to set. So in your case you don't need the webpart, just the user control that is inheriting the CMS namespaces and displaying the data.

I've personally done many Kentico websites with a few pages to sites with thousands of pages and integrate with different payment systems, web services, etc. and have never used ASPX development mode. Simply because it makes it difficult for the client to take advantage of Kentico's abilities when all the simple settings are done in code and a content editor has to know C# or ASP.NET. Once you learn how to create webparts it's really no different than making a user control.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.