public class TextBoxDerived : System.Web.UI.WebControls.TextBox
{
protected override void OnLoad(EventArgs e)
{
this.Controls.Add(new LiteralControl("Hello"));
}
}
The above code does not seem to do anything?
I was hoping something like
Hello
<input type"textbox" />
to be rendered in HTML.
A
TextBoxis not aCompositeControl, so it’s children won’t be rendered automatically.What you could do, for example, is overwriting the
Rendermethod and manually rendering the control beforehand.If you want to, as I assume, provide a textbox label and not some literal content, maybe using a
HtmlGenericControlwith aspanordivtag would be more suitable, in order to automatically render escaped text.