Creating a webpart with Editable Text

rex extreme asked on November 18, 2019 01:20

I'm trying to create a webpart that contains an editable text. I wanted to enable the content manager to edit the contents of the webpart without using the design view. Is it possible to do this? Is there a kentico way of implementing this?

I'm new to kentico and hoping that someone could point me to the right direction. Thanks in advance!

Correct Answer

Juraj Ondrus answered on November 18, 2019 07:10

I guess there is some more logic in the custom web part than the editing content. Anyway, it is possible. In this case you need to use the CMSEditableRegion control in the web part. Something like this (ASCX):

<% @ Control Language="C#" AutoEventWireup="true" Inherits="CMSWebParts_General_CustomWebPart" CodeFile="~/CMSWebParts/General/CustomWebPart.ascx.cs" %>  
<cms:CMSEditableRegion ID="TileTitle" runat="server" RegionType="TextBox" />    
<cms:CMSEditableRegion ID="TileDesc" runat="server" RegionType="HtmlEditor" />

And then, in the code behind, it is the same as for other web parts, just do not forget to inherit from CMSAbstractWebPart class:
public partial class CMSWebParts_General_CustomWebPart : CMSAbstractWebPart

2 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on November 18, 2019 21:52

Rex,

You might want to read a post which I had a pretty good answer to a few years ago. If you're still working in portal development mode, this article is still very valid no matter what version you are on.

https://devnet.kentico.com/questions/webparts-vs-widgets-vs-static-html

The short answer to your story is it sounds like you're using a static text web part OR are having a hard time placing an editable text webpart on a template and leaving it there. If this is the case, create a simple template with 1 zone in it and make the zone a widget zone. Then the user can add any number of rich text widgets to the page.

If I'm far off, read the answer to the post listed above.

1 votesVote for this answer Mark as a Correct answer

rex extreme answered on November 18, 2019 23:37 (last edited on November 19, 2019 00:07)

@juraj, Thanks, hopefully this works :)

@Brenden, Thanks for sharing the thread. I will read through it.

My goal is to simplify web part implementation. Getting rid of the tedious process of switching views in order to add contents. I wanted to create a web part with a template like behaviour. It should contain all basic content place holders like editable text and editable image that are editable in page view.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on November 19, 2019 13:17

Rex,

Simplifying web part implementation and getting rid of the tedious process of switching views in order to add contents could simply mean you don't understand the system and how it works. Before you do the "typical developer thing" and throw code at your solution, I'd highly suggest reading the answer in that thread and doing some tests of your own to better understand the system.

I'm actually a little surprised Juraj (Kentico Support) suggested that code before configuration. Simply attacking what you may think is a problem with code, can and will lead to a lifetime of nightmare upgrades, performance issues and overall maintenance headaches dealing with code which could have simply been configuration instead.

1 votesVote for this answer Mark as a Correct answer

rex extreme answered on November 21, 2019 23:49

Brendan,

I will heed your advice on this. It's clear that i lack understanding experience and understanding in kentico. I'd love to start learning the best practices in developing kentico modules. Thanks!

0 votesVote for this answer Mark as a Correct answer

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