实际应用中,遇到了这个问题,有以下三种解决方案:
方案一: 验证控件验证(经实践可行)
Setting the Maxength of a TextBox when it is in Multiline, You can use RegularExpressionValidator control as shown below :
<asp:TextBox ID="txtConclusion" MaxLength="200" TextMode="MultiLine" Height="100px" Width="400px" runat="server" />
<asp:RegularExpressionValidator ID="txtConclusionValidator1" ControlToValidate="txtConclusion" Text="超过200字" ValidationExpression="^[/s/S]{0,200}$" runat="server" />
方案二:弹出对话框提示
1.html代码



























2.cs代码




方案三: 自定义控件
Multiline TextBox with MaxLength Validation
http://www.codeproject.com/KB/aspnet/Textarea_Length_Validator.aspx