Handle TextArea / Multiline Textbox when using System.Web.UI.WebControls.Adapters.WebControlAdapter

If you are using a ASP:NET Web Control Adapter (System.Web.UI.WebControls.Adapters.WebControlAdapter) to give Textboxes a specific look'n'feel in your web application you might encounter a strange problem:

TextBoxes set to TextBox.TextMode = TextBoxMode.Multiline will not render any content / text

I found a couple of people experiencing this problem, but I haven't found a proper solution that was not "create your own textarea control"…

I believe that the problem is that when a TextBox is rendering Multiline-content, it is not rendering an <input>-Element but a <textarea>-Element. So the property TextBox.Text will not be rendered within the value-Attribute of the <Input> but within the <textarea>-Element, like a ChildControl, or better said as Element.InnerText. However, I have not investigated too much in what is going on.

A proper solution to address this issue is by overriding the RenderContents method and handle Multiline-Textboxes specifically:

        protected override void  RenderContents(HtmlTextWriter writer)
        {
            TextBox textBox = (TextBox)Control;
            if (textBox.TextMode == TextBoxMode.MultiLine)
                writer.Write(HttpUtility.HtmlEncode(textBox.Text));

          base.RenderContents(writer);
        }

Leave a Reply