本文介绍了错误帮助::用相同的ID'ctl00“多个控件被发现。 FindControl需要控件具有唯一的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

获取上述错误。
我想手风琴的ID是唯一的每次它必然。我在code..Its动态添加的手风琴窗格中不工作: -

是这样的: -

 的for(int i = 0; I< dt.Rows.Count;我++)
{AccordionPane ACCP =新AccordionPane();
accp.ID =ACCP+ i.ToString();
Accordion1.Panes.Add(ACCP);
Accordion1.DataSource = dt.DefaultView;
Accordion1.DataBind();
}

我要手风琴的ID是唯一的。我怎样才能做到我想要什么?

aspx页面: -

 < D​​IV ID =DIV1=服务器>
        < Telerik的:RadTabStrip ID =RadTabStrip1=服务器MultiPageID =RadMultiPage1OnTabClick =RadTabStrip1_OnTabClickClickSelectedTab =真>
        < / Telerik的:RadTabStrip>
< BR />< BR />
       < Telerik的:RadMultiPage ID =RadMultiPage1=服务器的SelectedIndex =0>       < / Telerik的:RadMultiPage>    < / DIV>          < CC1:手风琴ID =Accordion1=服务器FadeTransitions =真可见=真的AutoSize =无
                的SelectedIndex =0RequireOpenedPane =假TransitionDuration =250HeaderCssClass =accordionHeaderContentCssClass =accordionContent的CssClass =toggler>
                <&HeaderTemplate中GT;                    < B风格=颜色:黑色>                        <%#的eval(疑问句)%>
                    < / B>                < / HeaderTemplate中>
                <&的ContentTemplate GT;
                &所述p为H.; <%#DataBinder.Eval的(的Container.DataItem,QuesAns)%>< / P>                < /&的ContentTemplate GT;
            < / CC1:手风琴>
            < BR />


解决方案

您不应该调用 BindAccordion 多次,因为(我猜),这就是为什么你'再与具有相同ID的多个控件结束了。

您会在这两个的Page_Load RadTabStrip1_OnTabClick 调用它。从code我最好的猜测是,你应该只从的Page_Load !的IsPostBack 像你调用它一次已经。

如果还是不行,请尝试以下操作:

 保护无效BindTabStrip()
{
    DataSet的DS = GetDataSetForTabs();
    RadTabStrip1.AppendDataBoundItems = TRUE;
    RadTabStrip1.DataSource = DS;
    RadTabStrip1.DataTextField =QuesType;
    RadTabStrip1.DataValueField =QuesTypeID;
    RadTabStrip1.DataBind();    //将它添加到之前删除它从页面手风琴
    //一个新的ControlCollection
    Page.Controls.Remove(Accordian1);    RadPageView PV =新RadPageView();
    pv.Controls.Add(Accordion1);    RadMultiPage1.PageViews.Add(PV);
}

Getting the above Error.I want the IDs of the Accordian to be unique everytime it is bound. I added Accordian pane dynamically in my code..Its not working:-

like this :-

for(int i=0;i< dt.Rows.Count;i++)
{

AccordionPane accp = new AccordionPane();
accp.ID = "accp" + i.ToString();
Accordion1.Panes.Add(accp);
Accordion1.DataSource = dt.DefaultView;
Accordion1.DataBind();
}

I want the IDs of the Accordian to be unique. How can I accomplish what I want ?

Aspx Page:-

<div id="div1" runat="server">
        <telerik:RadTabStrip ID="RadTabStrip1" runat="server" MultiPageID="RadMultiPage1" OnTabClick="RadTabStrip1_OnTabClick" ClickSelectedTab="true">
        </telerik:RadTabStrip>
<br /><br />
       <telerik:RadMultiPage ID="RadMultiPage1" runat="server" SelectedIndex="0">

       </telerik:RadMultiPage>

    </div>

          <cc1:Accordion ID="Accordion1" runat="server" FadeTransitions="true"  Visible="true" AutoSize="None"
                SelectedIndex="0" RequireOpenedPane="false"  TransitionDuration="250" HeaderCssClass="accordionHeader" ContentCssClass="accordionContent" CssClass="toggler">
                <HeaderTemplate>

                    <b style="color: Black">

                        <%#Eval("Ques")%>
                    </b>

                </HeaderTemplate>


                <ContentTemplate>
                <p> <%#DataBinder.Eval(Container.DataItem, "QuesAns")%></p>

                </ContentTemplate>
            </cc1:Accordion>
            <br />
解决方案

You shouldn't be calling BindAccordion multiple times because (I'm guessing) that's why you're ending up with multiple controls with the same ID.

You're calling it in both Page_Load and RadTabStrip1_OnTabClick. My best guess from your code is that you should only call it once from Page_Load when !IsPostBack like you have already.

If that doesn't work, try the following:

protected void BindTabStrip()
{
    DataSet ds = GetDataSetForTabs();
    RadTabStrip1.AppendDataBoundItems = true;
    RadTabStrip1.DataSource = ds;
    RadTabStrip1.DataTextField = "QuesType";
    RadTabStrip1.DataValueField = "QuesTypeID";
    RadTabStrip1.DataBind();

    // Remove it accordian from the page before adding it to
    // a new ControlCollection
    Page.Controls.Remove(Accordian1);

    RadPageView pv = new RadPageView();
    pv.Controls.Add(Accordion1);

    RadMultiPage1.PageViews.Add(pv);
}

这篇关于错误帮助::用相同的ID'ctl00“多个控件被发现。 FindControl需要控件具有唯一的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 00:11