ASP.NET - Run time error - Asked By Sudhansu shekhar on 17-Nov-11 08:00 AM

Hi all

Multiple controls with the same ID '_header' were found. FindControl requires that controls have unique IDs. This kind of error i m getting while trying to run accordian in run time, this is the code:  protected void Page_Load(object sender, EventArgs e)
    {
       
       
        con.Open();
        SqlCommand cmd = new SqlCommand("Select * from ParentTable", con);
        int i = cmd.ExecuteNonQuery();
        SqlDataReader Sdr = cmd.ExecuteReader();
       
        string ParentNode;
        
       while (Sdr.Read())
        //for (int j = 1; j <= 2;j++ )
        {
            ParentNode = Sdr[0].ToString();
            string ss = "Select * from ChildTable where ParentId =" + ParentNode;
            con1.Open();
            SqlCommand cmd1 = new SqlCommand(ss, con1);
            SqlDataReader Module_Sdr = cmd1.ExecuteReader();
            Module_Sdr.Read();
            String Title = Sdr["ParentName"].ToString();
            String SubTitle = Module_Sdr["ChildName"].ToString();
            String PageTitle = Module_Sdr["Pagename"].ToString();
            Module_Sdr.Close();
            con1.Close();
            AccordionPane newAccordion = new AccordionPane();
            newAccordion.HeaderContainer.Controls.Add(new LiteralControl(Title));
            // newAccordion.ContentContainer.Controls.Add(new LiteralControl("SubTitle"));
            //newAccordion.ContentContainer.ForeColor = System.Drawing.Color.White;


            Accordion1.Panes.Add(newAccordion);


        }
        Sdr.Close();
        con.Close();
    }

Suchit shah replied to Sudhansu shekhar on 17-Nov-11 08:03 AM
In your ASPX page you have give same ID to the 2 Control so correct that same ID error and it get resolved
dipa ahuja replied to Sudhansu shekhar on 17-Nov-11 08:03 AM
The error is coming when two or more controls have the same id proeprty for ex:

<asp:Label ID="lblID" runat="server" Text="Label"></asp:Label>
<asp:Label ID="lblID" runat="server" Text="Label"></asp:Label>


This will cause the error of same ID

Kirtan Patel replied to Sudhansu shekhar on 17-Nov-11 08:10 AM
error is not coming from this code i think because according to error you have two controls with same ID in AccordianHeader correct that . this page load event not using any kind of FindControl() method .

check for duplicate ID of controls in your Accordion Control.

thanks
Reena Jain replied to Sudhansu shekhar on 17-Nov-11 09:40 AM
hi,

This is one of the common error we get when you use multiple panes in Accordion control. 


The problem is with duplicate ID for the panes. Setting unique ID's to dynamic panes will fix this issue

<cc1:accordion id="Accordion1" runat="Server" selectedindex="0" 
    autosize="None" fadetransitions="true" transitionduration="350"
  framespersecond="50" requireopenedpane="false" suppressheaderpostbacks="true">
</cc1:accordion>
In Code behind based on the number of panes:

for (int i = 0; i < 2; i++)
{
  AccordionPane pane1 = new AccordionPane();
  //use Guid here for uniqueness
  pane1.ID = "AccordionPane" + Guid.NewGuid().ToString();
  Label Label1 = new Label();
  Label1.Text = "New pane";
  pane1.Controls.Add(Label1);
  Accordion1.Panes.Add(pane1);
}

or if you simply put an ID and 'runat="server"' on each of your existing accordion panes, you should no longer get this error

kalpana aparnathi replied to Sudhansu shekhar on 17-Nov-11 01:00 PM
hi,
   "In your application only one control have only one id so please check your controls more than one control have same name"

s j replied to Sudhansu shekhar on 18-Nov-11 12:39 AM


Hi,

I think you are assigning two names to a single controls, means, while finding the control id using find control , you should we have to create an instance for that and we will assign it to the ID of that control.

Like this, you are assigning two instances to single ID of the control.


Plz check it once.and let me know the status.



Cheers,
Samantha.