I'm creating a control based on ScriptControl, and I'm overriding the Render
method like this:
protected override void Render(HtmlTextWriter writer)
{
RenderBeginTag(writer);
writer.RenderBeginTag(HtmlTextWriterTag.Div);
writer.Write("This is a test.");
writer.RenderEndTag();
RenderEndTag(writer);
}
My question is, what if I want to assign the div an ID attribute and have it be unique on the page, even if there are mulitple instances of my control?
I've seen other people's code that does this:
writer.AddAttribute(HtmlTextWriterAttribute.Id, this.ClientID + "_divTest");
That will prevent naming conflicts between instances of my control, but what if I've already created a div elsewhere on the page that coincidentally has the same ID?
I've also heard about implementing INamingContainer. Would that apply here? How could I use it?
UPDATE:
I've worked around this by overriding CreateChildControls
and adding actual controls, as opposed to rendering HTML directly. In that case INamingContainer does its job. However, I'm still curious if there's a way to solve my original problem (unique IDs for directly rendered elements).