Text Area (or) TextBox Maxlength doest not work when TextMode is set to Multiline


TextArea TextBox Maxlength doest not work when TextMode is set to Multiline

Hi,
This is known issue in ASP.NET Standard Text box control when set its TextMode="MultiLine" the MaxLength property does not work.
There is a workaround to accomplish this using RegularExpressionValidator. Following is the markup that will restrict the text box to maximum of 500 characters.

<asp:TextBox ID="txtComments" runat="server" TextMode="MultiLine" Height="100px"
Width="320px" MaxLength="10">asp:TextBox> <asp:RegularExpressionValidator
ID="regComments" runat="server" ControlToValidate="txtComments"
ValidationExpression="^[\s\S]{0,500}$" ErrorMessage="Maximum 500 characters are allowed in comments box." Text="Maximum 500 characters are allowed in comments
box." > asp:RegularExpressionValidator

No comments:

Post a Comment

Keep ur coding aside.. Relax for some time..