ASP.NET MaxLength Property

Definition and Usage

The MaxLength property is used to set or return the maximum number of allowed characters in the TextBox control.

Syntax

<asp:TextBox MaxLength="num" runat="server" />
Property Description
num A number, which specifies the maximum number of allowed characters in the text box.

Example

The following example sets the maximum number of allowed characters in the TextBox control:

<form runat="server">
<asp:TextBox id="tb1" runat="server" MaxLength="10" />
</form>

Example

Set the Maximum Length of TextBox Control