How to set the number of ROWS for a Multiline TextBox in ASP.NET?
You can easily use the ROWS
attribute in Multiline TextBox in ASP.NET to just limit the DISPLAYED number of ROWS.
<asp:TextBox class="form-control" ID="txt_messageBody" runat="server" TextMode="MultiLine" Rows="5"></asp:TextBox>
How to limit the character numbers for a Multiline TextBox in ASP.NET?
The above solution will limit the displayed number of rows in Multiline TextBox, but it will not limit the MAX number of characters.
To set the Minimum and Maximum number of characters in MultiLine TextBox in ASP.NET, you can use asp:RegularExpressionValidator
as below
<asp:TextBox class="form-control" ID="txt_messageBody" runat="server" TextMode="MultiLine" Rows="5"></asp:TextBox>
<asp:RegularExpressionValidator Display ="Dynamic" ControlToValidate ="txt_messageBody" ID="RegularExpressionValidator1" ValidationExpression = "^[\s\S]{50,200}$" runat="server" ErrorMessage="You should provide at least 50 charachters (Maximum 200 characters)" ValidationGroup="contactForm"></asp:RegularExpressionValidator>
For Single line TextBox, you can use MaxLength
attribute as below:
<asp:TextBox ID="TextBox1" MaxLength="200" runat="server"/>