Hi,
I have written a custom server control which (pseudo-code) looks like
public class MyCustomCtrl : WebControl
{
private Button innerCtrl; //some arbitrary object, doesn't matter
...
protected override void CreateChildControls()
{
//initialization etc, as standard...
}
}
Now I have the case that I have to copy this custom server control. Basically it is added by the programmer declaratively on the aspx or ascx code. At run-time multiple instances of this control have to be created which are then added to some parent control. This is however handled in the context of that parent control.
Anyway, it is a bit difficult to explain the context of use. My main question however is on whether it is safe to use "cloning", especially to invoke the MemberwiseClone()
on web controls? What I did so far is to add a method like
public class MyCustomCtrl : WebControl
{
...
public object Clone(){
MyCustomCtrl clone = MemberwiseClone() as MyCustomCtrl;
clone.InnerCtrl = this.innerCtrl.Clone() as Button; //or whatever type
return clone;
}
}
I mean the ASP.net control hierarchy is quite a complex model. So I wanted to hear whether some of you knows any drawbacks that may occur with such a solution.