I'm working with a static class in C#, and am trying to use Control.RenderControl()
to get a string / mark-up representation of a Control
.
Unfortunately the control (and all child controls) use event bubbling to populate certain values, for example, when instantiating, then calling RenderControl()
on the following:
public class MyTest : Control
{
protected override void OnLoad(EventArgs e)
{
this.Controls.Add(new LiteralControl("TEST"));
base.OnLoad(e);
}
}
I am returned an empty string, because OnLoad()
is never fired.
Is there a way I can invoke a 'fake' page lifecycle? Perhaps use some dummy Page
control?