Home

ASP.NET Controls: The Memo Text Box

 

Memo Fundamentals

 

Introduction

A memo (this word was borrowed from C++Builder and Delphi; that is, from the Visual Component Library) text box is used to request text from the user and/or to display one or more paragraphs of text to the user. The memo is a variant of the text box.

 

Creating a Memo Text Box

To create a memo text 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 Memo Text Box

 

The Text of a Text Box

A memo text box is supposed to hold text. When it comes up, if you want the control to display text, if you are visually designing the web site, access the the Properties window for the text box, click Text and type the desired value. If you are working manually, add a Text attribute and assign the desired value to it. Here is an 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:

Memo

To get the text of a memo text 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:

Memo

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:

Memo

 
 
 
 

The Number of Rows of a Memo Text Box

 

As mentioned already, after you have added a text box and change it into a memo, it assumes some default dimensions about the height and the width. We know that you can control the width of a text box by assigning a value to the Columns attribute. To assist you with the height of a memo, you measure it in terms of the height of a character. This characteristic is controlled by the Rows attribute, which represents the number of visible lines of the memo.

To specify the number of lines of text that the memo can show at one time, assign a value to the Rows attribute. 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"
       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:

Memo

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:

Memo

 
 
   
 

Home Copyright © 2009-2016, FunctionX, Inc.