Groups | Blog | Home
all groups > asp.net webcontrols > november 2004 >

asp.net webcontrols : INamingContainer problem...can I work around this?


R. Myers
11/27/2004 10:01:59 AM
I have implemented INamingContainer in a custom WebControl. It provides
unique ID's for controls without ID's. However, if my control already has
an ID set in its property panel, or in code, The HTML that is rendered
always shows the unique ID in front of it.

If the ID is "Table1", it renders as _ct10_Table1". Is there any way to get
the ID to be exactly as provided, and only supply the unique ID's for
controls without ID's?


rmyers NO[at]SPAM everestkc.net
11/27/2004 11:29:07 AM
[quoted text, click to view]

O.K. I think I got it now. I misunderstood the use of
CreateChildControls. If I understand it correctly, I can add any
number of objects of various types to the Controls collection just to
get a unique name. Then when I render the control, I can reference
each object in the controls collection by index, and render them as
needed. They don't all need to be of the same type.

For example, I can add a TableRow, and 5 TableCell's to my control.
Then I can render as follows:

protected override void Render(HtmlTextWriter output)
{
m_Table.Rows.Add((TableRow)this.Controls[0]);

for (int i = 1; i < this.Controls.Count; i++)
{
m_Table.Rows[0].Cells.Add((TableCell)this.Controls[i]);
}

m_Table.RenderControl(output);
}

AddThis Social Bookmark Button