HtmlTextArea Server Control Declarative Syntax
Creates a server-side control that maps to the <textarea> HTML element and allows you create a multiline text box.
<textarea
EnableViewState="False|True"
Id="string"
Visible="False|True"
OnDataBinding="OnDataBinding event handler"
OnDisposed="OnDisposed event handler"
OnInit="OnInit event handler"
OnLoad="OnLoad event handler"
OnPreRender="OnPreRender event handler"
OnServerChange="OnServerChange event handler"
OnUnload="OnUnload event handler"
runat="server"
>
<!-- Control Content -->
</textarea>
Remarks
Use the HtmlTextArea control to program against the HTML <textarea> element. This control allows you to create a multiline text box. The dimensions of the text box are controlled by the Cols and Rows properties. The Cols property determines the width of the control, while the Rows property determines the height of the control.
The HtmlTextArea control contains a ServerChange event that is raised when the contents of the control change between posts to the server. The event is commonly used to validate the text entered in the control.
Example
The following example demonstrates how to use the OnServerClick event handler of an HtmlInputButton control to display user input from an HtmlTextArea control. The text is displayed by a span control in the Web Forms page. You can use similar techniques to store the text area's values on the server.
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>HtmlTextArea Control</title>
<script runat="server">
Sub SubmitBtn_Click(sender As Object, e As EventArgs)
Span1.InnerHtml = "You wrote: <br />" & TextArea1.Value
End Sub
</script>
</head>
<body>
<h3>HtmlTextArea Example</h3>
<form id="Form1" runat="server">
What do you like best about ASP.NET?: <br />
<textarea id="TextArea1" cols="40" rows="4" runat="server" />
<input id="Submit1" type="submit" value="Submit"
onserverclick="SubmitBtn_Click" runat="server" />
<br />
<span id="Span1" runat="server" />
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>HtmlTextArea Control</title>
<script runat="server">
void SubmitBtn_Click(Object sender, EventArgs e)
{
Span1.InnerHtml = "You wrote: <br />" + TextArea1.Value;
}
</script>
</head>
<body>
<h3>HtmlTextArea Example</h3>
<form id="Form1" runat="server">
What do you like best about ASP.NET?: <br />
<textarea id="TextArea1" cols="40" rows="4" runat="server" />
<input id="Submit1" type="submit" value="Submit"
onserverclick="SubmitBtn_Click" runat="server" />
<br />
<span id="Span1" runat="server" />
</form>
</body>
</html>
See Also
Reference
HtmlTextArea
System.Web.UI.HtmlControls