How to add multiple custom web parts with multiple editable text web parts in it

If you create custom web part where you put multiple editable text web parts and then add multiple instances of this web part into page then all instances are showing the same content in each editable region. This article describes how to avoid this behavior.
This issue is caused by there is ID of editable text web part used for identifying content in DB and it's always the ID that you have specified in your web part even if you add multiple instances of your web part to the page. You need to ensure the ID is different for each instance of your custom web part. Please find sample procedure bellow:

1) Create custom web part and add following controls into it (please note you need to use editable web parts in your custom web part, you can't use editable region controls in this case):

<%@ Register src="../Text/editabletext.ascx" tagname="editabletext" tagprefix="uc1" %>

<uc1:editabletext ID="text1" runat="server" DialogHeight="158" DialogWidth="168" WordWrap="true" />
<uc1:editabletext ID="text2" runat="server" DialogHeight="158" DialogWidth="168" WordWrap="true" /

2) Add following code into OnContentLoaded() method in code-behind of your web part. Basically it will concatenate ID of each editable text web part with ID of your web part specified in 'Desing -> configure your web part -> Web part control ID' property:

        text1.ID = this.GetValue("WebPartControlID").ToString() + this.text1.ID;
        text2.ID = this.GetValue("WebPartControlID").ToString() + this.text2.ID;

3) You can now add two or more instances of your web part to the same page and specify the content into them and the content should not be change after saving changes and refresh of page.


See also:

Applies to: Kentico CMS 5.5 (should work in previous versions as well)
Share this article on   LinkedIn