Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Adding the same webpart more than once View modes: 
User avatar
Certified Developer v7
Certified  Developer v7
emanuele.firmani-aduno-gruppe - 4/19/2010 10:04:18 AM
   
Adding the same webpart more than once
I created a webpart with the following code:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="HomeImageBox.ascx.cs" Inherits="CMSWebParts_aduno_gruppe_HomeImageBox" %>
<%@ Register Assembly="CMS.Controls" Namespace="CMS.Controls" TagPrefix="cc1" %>

<div class="homeBox">
<div class="logoImage"><cc1:CMSEditableImage ID="Title" runat="server" /></div><div class="clear"></div>
<div class="image"><cc1:CMSEditableImage ID="Banner" runat="server" /></div>
<div class="text"><cc1:CMSEditableRegion ID="Text" runat="server" /></div>
</div>
<asp:Literal Text="<div class='separator'></div>" runat="server" ID="litSeparator" Visible="false" />

I added this webpart three times in the same page, but it shows always the same content. I took a look at the DB and I found a row in the table CMS_Document where the corresponging XML has only one node for region "banner", "text" and "title", not three as I expected.
When I added three times the webpart, I used three different Web Part Control ID.

Am I wrong? How can I achieve my goal? I don't want to create three webparts, just add it three times.

Many thanks
Regards
Emanuele Firmani

User avatar
Kentico Developer
Kentico Developer
kentico_martind - 4/21/2010 1:51:56 PM
   
RE:Adding the same webpart more than once
Hi Emanuele,

There is ID of editable text used when storing content in DB - and it's always the same in each instance of your web part. You could solve this issue by adding code which will generate unique ID for these editable text web parts. You can set ID of editable text e.g. as concatenation of editable text web part's ID and your custom webpart ID (you can ensure this e.g. in OnContentLoaded event of custom web part). This procedure should ensure that every editable text in each instance of your custom webpart has unique ID.

Please make also sure to use Editable text/Editable image web parts in your web part as this procedure doesn't work for CMSEditableRegion/CMSEditableImage controls due to security reasons.

Best Regards,

Martin Dobsicek

User avatar
Certified Developer v7
Certified  Developer v7
emanuele.firmani-aduno-gruppe - 4/22/2010 7:43:40 AM
   
RE:Adding the same webpart more than once
I created a new unique ID in the OnContentLoaded event and I was able to set different content in different webparts.
The problem now is that I can see the content as long as I'm logged in. If I open the same URL with another browser or log off, I won't see anything. Can you explain me why, please?
Update: I applied the advice "make also sure to use Editable text/Editable image web parts in your web part" and everything worked fine. The new code is:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ImageBox.ascx.cs" Inherits="CMSWebParts_aduno_gruppe_ImageBox" %>
<%@ Register src="../Text/editableimage.ascx" tagname="editableimage" tagprefix="uc1" %>
<%@ Register src="../Text/editabletext.ascx" tagname="editabletext" tagprefix="uc2" %>

<div class="imageBlock">
<div class="imageBlock"><uc1:editableimage ID="Banner" runat="server" /></div>
<div class="text"><uc2:editabletext ID="Text" runat="server" DialogHeight="158" DialogWidth="168" WordWrap="true" /></div>
</div>


Consider closed this issue.
Many thanks
Regards
Emanuele Firmani