1

我有这个令人难以置信的问题,使用 ASP Accordion Control。我正在尝试在同一个 WebForm ASP 页面上动态创建多个手风琴。这是一个示例代码:

for(int i = 1; i <= 12; ++i)
{
    Accordion accordion = new Accordion();
    accordion.ID = customerName + "_Accordion";
    accordion.Panes.Add(accordionPane); // accordionPane: Other dynamically created AccordionPane Control

    this.Panel.Controls.Add(accordion); // Panel: An asp Panel Control in the page
}

当我在浏览器上加载页面时,出现此错误:

“找到了具有相同 ID '_AccordionExtender' 的多个控件。”

我怀疑手风琴控件会在页面上自动添加 AccordionExtender,但我非常需要在后面的代码上动态创建这些手风琴。如果我在 aspx 页面中以声明方式添加手风琴,为什么不会出现此错误?这个问题有解决方案吗?谢谢大家!

4

1 回答 1

1

尝试这个

    for(int i = 1; i <= 12; ++i)
{
    Accordion accordion = new Accordion();
    accordion.ID = customerName + "_Accordion" + i.toString();
    accordion.Panes.Add(accordionPane); // accordionPane: Other dynamically created AccordionPane Control

    this.Panel.Controls.Add(accordion); // Panel: An asp Panel Control in the page
}
于 2013-01-02T11:10:41.093 回答