Tuesday 25 November 2014

Create custom webpart and register it in kentico CMS

Create Your Own Custom Web Parts : 

Web parts are page components that provide a combination of content and functionality. 
Web parts exist on three different levels:
Code filesOn the most basic level, web parts are user controls (.ascx files) that inherit from an appropriate base class.
System objects
Web parts must be registered as objects in the system. The purpose of the objects is to:
  • Specify the path to the user control source file
  • Define the web part's properties and store other configuration options
Page components
Web parts placed onto page templates are called web part instances. You can create any number of instances of a single web part.
Instances must be inserted into web part zones, which are defined within the layouts of page templates.

 A new web parts consists of two basic steps:

  1. Create the web part's code files in your web project.




1) Open the WebProject solution created at the time of installing Kentico.

2) Within the folder 'CMSWebParts' create a new folder lets say 'CustomWebParts'.
3) Create a new UserControl(ascx file) with required functionality within this folder(Let the name is MyCustomWebPart.ascx).

4) Add the following line to the beginning of the code:Example in C# :-using CMS.PortalControls;

5) In the ascx file we have to change the following lines:-
public partial classCMSWebParts_CustomWebParts_MyCustomWebPart

System.Web.UI.UserControl public partial class

CMSWebParts_CustomWebParts_MyCustomWebPart: CMSAbstractWebPart

CMSWebParts_CustomWebParts_MyCustomWebPartCMSAbstractWebPar

to public partial class

2. Register the web part in the cms system.

  1. Open the Web parts application.
  2. Select the category where you want to place the web part.
  3. Click New web part.
  4. Type a Display name for the web part.
  5. Specify the path of the user control in the File path field.
  6. Click Save.
  7. Define the properties of the web part. See Working with web part properties for more information.
 Before you can use your user controls as web parts, you need to register them as objects in Kentico. The system sorts web parts into categories, organized in a tree structure.
Implement web parts as user controls (.ascx files) that inherit from an appropriate base class:
Base class
Use for
CMSAbstractWebPartStandard web parts.
CMSAbstractEditableWebPart
Web parts that provide content editing functionality on the Page tab of the Pages application and in on-site editing mode (such as Editable text or Editable image).
CMSAbstractLanguageWebPartWeb parts that allow users to switch between languages on multilingual websites.
CMSAbstractLayoutWebPart



1 comment:

  1. Kentico 13 xperience upgrade A very awesome blog post. We are really grateful for your blog post. You will find a lot of approaches after visiting your post.

    ReplyDelete