title: How to create a derived TextBox control?
body: <p>I need to create a custom TextBox control that allows user input HTML tags. I added a new property called HtmlEnabled, default is false. If it is false, it will act exactly like the original TextBox; if it is set to true, it will call Server.HtmlEncode to encode the text. I never creat a custom control, can anyone tell me what do I need to do? What function I need to override? Thanks.</p>
  
  <p>I created my TextBoxEx class as following: I still get the validation error when I set HtmlEnabled to true, can anybody tell me what is wrong?</p>
  
  <pre><code>namespace WebApplication1
  {
      [ToolboxData("&lt;{0}:TextBoxEx runat=server&gt;&lt;/{0}:TextBoxEx")]
      public class TextBoxEx : System.Web.UI.WebControls.TextBox
      {
          public bool HtmlEnabled
          {
              get
              {
                  return (bool)ViewState["HtmlEnabled"];
              }
              set
              {
                  ViewState["HtmlEnabled"] = value;
              }
          }
  
          public TextBoxEx()
          {
              ViewState["HtmlEnabled"] = false;
          }
  
          public override string Text
          {
              get
              {
                  if (HtmlEnabled)
                      return HttpUtility.HtmlEncode(base.Text);
                  else return base.Text;
              }
  
              set
              {
                  if (HtmlEnabled)
                      base.Text = HttpUtility.HtmlDecode(value);
                  else base.Text = value;
              }
          }
  
  
      }
  }
  </code></pre>