Thursday, August 13, 2009

Tip to Validate MaxLength property of Textbox when Textmode is set to Multiline

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 100 characters.


<asp:TextBox ID="txtAddress" runat="server" TextMode="MultiLine" Height="100px"
Width="320px" MaxLength="10"> </asp:TextBox>

<asp:RegularExpressionValidator ID="Address" runat="server" ControlToValidate="txtAddress" ValidationExpression="^[\s\S]{0,100}$" ErrorMessage="Maximum 100 characters are allowed in Address box." Text="Maximum 100 characters are allowed in Address box." > </asp:RegularExpressionValidator >

Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

0 comments : on " Tip to Validate MaxLength property of Textbox when Textmode is set to Multiline "