The id 'ctrl1' is already used by another control

The id 'ctrl1' is already used by another control

Post by Jacek » Fri, 31 Aug 2001 21:59:20

Hi all.
Why I get this error msg?
My code:

SQLCommand sqlCommand = new SQLCommand(txbQuery.Text, myConnection);
SQLDataReader dr;
sqlCommand.Execute(out dr);

TableRow tbRow = new TableRow();
TableCell tbCell = new TableCell();

    DataGrid dgGrid = new DataGrid();
    dgGrid.DataSource=dr; // *


tbCell.Controls.Add(new LiteralControl("Nothing"));

tbQuery.Rows.Add(tbRow);  // <- here is the line with error msg

When I remove * line everything is ok.
I cannot find ctrl1, but every time I get this error.

Thank you for any help.


1. The id 'ctrl1' is already used by another control

Has anyone solved this error? I am creating a composite control that creates a
dataset which gets data from the authors table in pubs and then binds to a
DataGrid. The error occurs when the DataGrid is added to the Controls collection.

Here is the code sample:

public class MyCtrl : Control
   protected override void CreateChildControls()
      SQLConnection oConnection = new SQLConnection(sConnStr);
      SQLCommand oCommand = new SQLCommand("select * from authors", oConnection);
      SQLDataSetCommand dsCmd = new SQLDataSetCommand("select * from authors",
      DataSet ds = new DataSet();
      dsCmd.FillDataSet(ds, "authors");

      System.Web.UI.WebControls.DataGrid authors = new
      authors.DataSource = ds.Tables["authors"].DefaultView;
      authors.ID = "authid";

      Controls.Add(authors);    // error happens here

2. Adaptec 1740 and Sony CDU-541

3. Composite Control Prob - Multiple controls with the same ID '_ctl0' were found

4. I'm headed for the shows!

5. User Control Instances and how .NET Prefixes control collection's ID's

6. Motherboards

7. Can't get the value of a text box using it's ID

8. Doc Says "Sorry All"

9. Validation error: Unable to find control id referenced by the 'ControlToValidate' property

10. MSDN survey sample problem - column named 'Answer' already belongs to this D

11. OleDbException: Could not use ''; file already in use.

12. Using 'double x' in VC++ gives 'float x'?

13. Error - Could not use ''; file already in use.- please help!