INamingContainer problem...can I work around this?

R

R. Myers

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?
 
R

R. Myers

R. Myers said:
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?

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);
}

m_Table.RenderControl(output);
}

This works. If I'm missing anything please let me know.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top