ASP.NET Controls: The Text Area Box
A text area box is used to request or to display one or more paragraphs of text to the user. This is a variant of the text box. It uses many lines for its…
ASP.NET Controls: The Text Area Box
ASP.NET Controls: The Text Area Box#
Memo Fundamentals#
Introduction#
A text area box allows users to input or view one or more paragraphs. This control is a specific type of text box that supports multiple lines, extending vertically as needed. If the entered text exceeds the control's height, scroll bars can be displayed for navigation.
Creating a Text Area Box#
To create a text area box, you first add a normal text box before configuring it. You can add a text box visually or manually. Here is an example:
<%@ Page Language="C#" %>
<html>
<head>
<title>Exercise</title>
</head>
<body>
<form id="frmTimeSheet" runat="server">
<asp:TextBox ID="txtNotes" runat="server"></asp:TextBox>
</form>
</body>
</html>Characteristics of a Text Area Box#
The Text of a Text Box#
A text area box is intended to contain text. If you want the control to show a value upon loading while visually designing the site, you can use the Properties window, click Text, and enter your string. For manual implementation, simply add a Text attribute and assign the desired value to it. For example:
<%@ Page Language="C#" %>
<html>
<head>
<title>Exercise</title>
</head>
<body>
<form id="frmTimeSheet" runat="server">
<asp:TextBox ID="txtNotes"
Text="I worked 14.50 hours on Tuesday but, to avoid
overtime, I was asked to sign 8 hours on
Tuesday and 6 hours on Friday."
runat="server"></asp:TextBox>
</form>
</body>
</html>This would produce:
To get the text of a text area box, type the ID of the control, followed by a period, followed by Text. On the other hand, to make the memo display one or more paragraphs, assign a value to Text. When the content of a memo has been changed, the text box fires a TextChanged event, which is of type EventArgs. When a visitor has finished using a text box and clicks a button, the values are sent to the server. If you want this to be automatic, set the value of the AutoPostBack Boolean attribute.
The Text Mode of a Text Box#
To transform a normal text box into a memo, you must change the value of an attribute named TextBox. This attribute uses a member of the TextBoxMode enumeration. The members of this enumeration are SingleLine, MultiLine, and Password. To create a memo, set this attribute to Multiline. Here is an example:
<%@ Page Language="C#" %>
<html>
<head>
<title>Exercise</title>
</head>
<body>
<form id="frmTimeSheet" runat="server">
<asp:TextBox ID="txtNotes"
TextMode="Multiline"
Text="I worked 14.50 hours on Tuesday but, to avoid
overtime, I was asked to sign 8 hours on
Tuesday and 6 hours on Friday."
runat="server"></asp:TextBox>
</form>
</body>
</html>The above code would produce:
If you are visually designing the web site, access the Properties window of the text box, click TextMode and select Multiline from the field. If you want to control the width of a memo, assign a number to Columns attribute of the <asp:TextBox> tag. Here is an example:
<%@ Page Language="C#" %>
<html>
<head>
<title>Exercise</title>
</head>
<body>
<form id="frmTimeSheet" runat="server">
<asp:TextBox ID="txtNotes"
TextMode="Multiline"
Columns="28"
Rows="4"
Text="I worked 14.50 hours on Tuesday but, to avoid
overtime, I was asked to sign 8 hours on
Tuesday and 6 hours on Friday."
runat="server"></asp:TextBox>
</form>
</body>
</html>This would produce:
The Number of Rows of a Text Area Box#
As previously noted, once you've added a text box and converted it to a memo, it adopts certain default dimensions for height and width. While the Columns attribute allows you to manage the width, the height of a memo is measured by character height. This is controlled by the Rows attribute, representing the number of lines visible at one time. To set how many lines are shown, assign a value to this attribute. For instance:
<%@ Page Language="C#" %>
<html>
<head>
<title>Exercise</title>
</head>
<body>
<form id="frmTimeSheet" runat="server">
<asp:TextBox ID="txtNotes"
TextMode="Multiline"
Columns="25"
Rows="4"
Text="I worked 14.50 hours on Tuesday but, to avoid
overtime, I was asked to sign 8 hours on
Tuesday and 6 hours on Friday."
runat="server"></asp:TextBox>
</form>
</body>
</html>This would produce:
Wrapping Text on a Memo#
When text is added to a memo, the operating system calculates the length of the text. If the text is too long with regards to the width of the control, a vertical scroll bar is added to it so the line can be interrupted and continue on the next. Wrapping is a characteristic of a memo that consists of continuing the text even if it is longer that the memo can show. To control this characteristic, the <asp:TextBox> tag is equipped with a Boolean attribute named Wrap. The default value of the Wrap attribute is True. If you to change it, set its value accordingly. Here is an example:
<%@ Page Language="C#" %>
<html>
<head>
<title>Exercise</title>
</head>
<body>
<form id="frmTimeSheet" runat="server">
<asp:TextBox ID="txtNotes"
TextMode="Multiline"
Columns="25"
Rows="4"
Wrap="False"
Text="I worked 14.50 hours on Tuesday but, to avoid
overtime, I was asked to sign 8 hours on
Tuesday and 6 hours on Friday."
runat="server"></asp:TextBox>
</form>
</body>
</html>This would produce:
Home Copyright © 2009 C# Key

