当文本框的模式设定为多行时,maxlength属性就无效了,这时可以使用RegularExpressionValidator控件,代码如下:
代码
< asp:TextBox ID ="txtIntroduct" runat ="server" TextMode ="MultiLine" Height ="120px" Width ="240px" class ="input_text" /> < asp:RegularExpressionValidator ID ="RegularExpressionValidator2" ControlToValidate ="txtIntroduct" ValidationExpression ="([^.]|.){0,300}" runat ="server" SetFocusOnError ="true" Display ="None" ValidationGroup ="AddApply" ErrorMessage ="简单的介绍,300字以内!" ></ asp:RegularExpressionValidator > < cc1:ValidatorCalloutExtender ID ="ValidatorCalloutExtender11" HighlightCssClass ="validatorCalloutHighlight" runat ="server" Enabled ="True" TargetControlID ="RegularExpressionValidator2" > </ cc1:ValidatorCalloutExtender >
单行时就用maxlength属性//限制只能输入25个字
<asp:TextBox ID="name" runat="server" Width="350px" MaxLength="25" ></asp:TextBox>