I would like to extend ASP.NET's Textbox control so I can make it into a WYSIWYG editor using TinyMCE. I would also like to add a hidden field to this Textbox control and store markdown in this hidden value from the client's browser and post it back to the server when the form submits.
The problem is this hidden field is not rendering it even though I have added it to collection of controls - only the textbox renders. How do I get the textbox AND hidden field to render?
The following code demonstrates how I'm extending the Textbox control.
public class TinyMCEEditor : System.Web.UI.WebControls.TextBox
{
private readonly HiddenField hf_MarkdownValue = new HiddenField();
public string MarkDown
{
get { return hf_MarkdownValue.Value; }
}
protected override void OnInit(EventArgs e)
{
//Adding the hidden field does not render
this.Controls.Add(hf_MarkdownValue);
base.OnInit(e);
}
}
The hidden field is not getting rendered at the client side since you are not rendering it. Add the following piece of code to your class an it would work fine: