Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > "Multiple controls with the same ID" View modes: 
User avatar
Certified Developer v7
Certified  Developer v7
chris.hewitt-precedent.co - 1/2/2013 11:21:23 AM
   
"Multiple controls with the same ID"
Hi All,

Just wondering, due to crowd experience, that anyone's come up with this issue before?

The background behind this:
- Created a custom Layout webpart (CMSAbstractLayoutWebPart)
- This has been added as a widget, via the page editor.
- Add a widget to one of the "Zones"
- YSOD.

Now, oddly this has been working before. And pages that currently have this Layout widget are fine, until you add a new widget, then the whole page breaks.

If anyone knows a good solution :)

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 1/4/2013 3:37:00 AM
   
RE:"Multiple controls with the same ID"
Hi,

When you use the pre-defined layout webparts/widgets - are they working OK?
Would it be possible to post here the code of your custom web parts?
Also, what everything is on given page - what other web parts and widgets?

Best regards,
Juraj Ondrus

User avatar
Certified Developer v7
Certified  Developer v7
chris.hewitt-precedent.co - 1/4/2013 5:42:01 AM
   
RE:"Multiple controls with the same ID"
Sure.. Pasted below.

However, it's not just the custom Layouts that are broken. If I try adding a builtin Widget to a builtin Widget Layout in a blank Template, I get the same issue.

 public partial class CssColumnLayout : CMSAbstractLayoutWebPart
{
private string mWebPartControlId;
//private bool mHaveChecked;
#region "Public properties"

public string ColumnSplit
{
get
{
return ValidationHelper.GetString(this.GetValue("ColumnSplit"), "3-3");
}
set
{
this.SetValue("ColumnSplit", value);
}
}

public string WebPartControlId
{
get
{
if (string.IsNullOrWhiteSpace(mWebPartControlId))
{
this.mWebPartControlId = string.Format("{1}", this.GetValue("WebPartControlID"), this.PartInstance.InstanceGUID);
}
return this.mWebPartControlId;
}
set
{
this.mWebPartControlId = value;
this.SetValue("WebPartControlID", value);
}
}

#endregion "Public properties"

#region "Methods"

/// <summary>
/// Prepares the layout of the web part.
/// </summary>
protected override void PrepareLayout()
{
if (this.Ancestors().Count(c => c.ID == base.ID) > 0)
{
this.WebPartControlId = this.PartInstance.InstanceGUID.ToString();
}

StartLayout();

int[] columnWidths = GetColumnWidths(this.ColumnSplit);

var columnId = 1;
var columnsTot = columnWidths.Sum();
var nestedLayout = false;

var layoutId = this.WebPartControlId;

Append(String.Format("<div class=\"column-layout-width-{0}\"", columnsTot));
if (IsDesign)
{
Append(" id=\"", this.WebPartControlId, "_env\"");

}
Append(">");

foreach (var width in columnWidths)
{
var columnIdent = string.Empty;
var panelId = string.Format("{0}_{1}wpc", this.WebPartControlId, columnId);
var zoneId = string.Format("{0}_{1}", this.ID, columnId);

if (columnId == 1) { columnIdent = " column-item-first"; }
if (columnId == columnWidths.Length) { columnIdent = " column-item-last"; }

var panel = new Panel()
{
CssClass = string.Format("column-item column-layout-width-{0}-{1}{2}", width, columnsTot, columnIdent),
};

if (IsDesign) { panel.ID = zoneId; }
if (zoneId == this.ID) { zoneId = zoneId + "wpz"; }

var zone = AddZone(zoneId, "Column " + columnId.ToString(), panel);

columnId += 1;
AddControl(panel);
}

Append("<div class=\"clear\"></div></div>");

FinishLayout();
}

private int[] GetColumnWidths(string columnSort)
{
switch (columnSort)
{
case "3-3":
return new int[] { 3, 3 };
case "4-2":
return new int[] { 4, 2 };
case "2-2-2":
return new int[] { 2, 2, 2 };
case "2-4":
return new int[] { 2, 4 };

case "4-4":
return new int[] { 4, 4 };
case "2-4-2":
return new int[] { 2, 4, 2 };
case "6-2":
return new int[] { 6, 2 };

case "2-2":
return new int[] { 2, 2 };

case "2-2-2-2":
return new int[] { 2, 2, 2, 2 };
default:
return new int[] { 3, 3 };
}
}

#endregion "Methods"
}

User avatar
Certified Developer v7
Certified  Developer v7
chris.hewitt-precedent.co - 1/4/2013 5:43:42 AM
   
RE:"Multiple controls with the same ID"
I know I should really convert the GetColumnWidths() to a split/parse. But haven't gotten round to that yet. Bigger issues an all that.

User avatar
Certified Developer v7
Certified  Developer v7
chris.hewitt-precedent.co - 1/4/2013 6:10:29 AM
   
RE:"Multiple controls with the same ID"
Oddly, the "Duplicate ID" error seems to be child widget dependent, which I'm not really sure why this is the case tbh.

If I abstract common properties / overrides, is it possible that these children widgets need to directly inherit from CMSAbstractWebPart?

Chris.

User avatar
Certified Developer v7
Certified  Developer v7
chris.hewitt-precedent.co - 1/4/2013 7:17:51 AM
   
RE:"Multiple controls with the same ID"
Never mind.

Found the issue. Another widget was throwing an error, but seems like the layout was trying to add it's zone again after failing the first time.

Is there a widget catch all for this type of issue? eg. some kind of BeginContext Helper?

Chris.

User avatar
Certified Developer v7
Certified  Developer v7
chris.hewitt-precedent.co - 1/7/2013 11:48:03 AM
   
RE:"Multiple controls with the same ID"
Also, For future reference..

If you are manually constructing a Layout and adding controls programatically, "AddZone" needs to be done last.

Just a FYI if anyone comes across this.

Chris.