Freigeben über


HtmlTextArea Control

Creates a server-side control that maps to the <textarea> HTML element and allows you create a multiline text box.

<textarea id="programmaticID"
          cols="numberofcolsintextarea"
          name="namepassedtobrowser"
          rows="numberofrowsintextarea"
          onserverchange="onserverchangehandler" 
          runat="server" >
textareacontent
</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" %>
<html>
<head>
   <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 runat=server>
      What do you like best about ASP.NET?: <br>
      <textarea id="TextArea1" cols=40 rows=4 runat=server />
      <input type=submit value="Submit" 
             OnServerClick="SubmitBtn_Click" runat=server>
      <p>
      <span id="Span1" runat="server" />
   </form>
</body>
</html>
[C#]
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>
   <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 runat=server>
      What do you like best about ASP.NET?: <br>
      <textarea id="TextArea1" cols=40 rows=4 runat=server />
      <input type=submit value="Submit" 
             OnServerClick="SubmitBtn_Click" runat=server>
      <p>
      <span id="Span1" runat="server" />
   </form>
</body>
</html>

See Also

ASP.NET Syntax for HTML Controls | HtmlTextArea Class | System.Web.UI.HtmlControls Namespace