My main question is: in .NET, how to clone WebControls?
I would like to create a custom tag that can create multiple copies of its children. Ultimately, I intend to create a tag similar to JSP / Struts.
But the first hurdle that I have is the ability to duplicate / clone the contents of the control.
Consider this rather contrived example:
<custom:duplicate count="2">
<div>
<p>Some html</p>
<asp:TextBox id="tb1" runat="server" />
</div>
</custom:duplicate>
The HTML markup that is output will be something like
<div>
<p>Some html</p>
<input type="text" id="tb1" />
</div>
<div>
<p>Some html</p>
<input type="text" id="tb1" />
</div>
Note. I know that I have a duplicate id, I can come up with this solution later!
So, we will have my user control with 3 children (I think) - a literal control, a TextBox control and another literal control.
"count = 2", , , / .
"OnInit", - :
List<WebControl> clones;
for(int i=1; i<count; i++)
{
foreach(WebControl c in Controls)
{
WebControl clone = c.Clone();
clones.Add(clone);
}
}
Controls.AddRange(clones);
, , WebControls ICloneable, .
, WebControls?