I have a simple class inheriting from WebControl as follow:
public class Instrument : WebControl
{
private SpecialItem myItem = new SpecialItem("ABC");
protected override void Render(HtmlTextWriter output)
{
output.Write("<div>");
myItem.RenderControl(output);
output.Write("</div>");
}
}
Once the control is added to a web page, the SpecialItem gets displayed but its inner “Load” method is never fired which makes it unusable. If I use the SpecialItem control on its own then it works as expected. How do you I make the load method from the SpecialItem control get executed?
Add
myItemto theControlscollection of your custom control. You typically do this (as well as instantiating the child controls) by overriding the methodCreateChildControls: