Click here to Skip to main content
15,923,006 members
Please Sign up or sign in to vote.
3.40/5 (2 votes)
See more:
I want to enter maximum of 100 characters only in a textbox. I used the following code but it allows beyond 100 characters. Can any one guide me?

XML
<asp:TextBox ID="TextBox3" runat="server" TextMode="MultiLine" MaxLength="100"
 OnTextChanged="TextBox3_TextChanged" Font-Size="Medium"
           style="z-index: 1; left: 930px; top: 178px; position: absolute;height: 40px; width: 225px"></asp:TextBox>


Thanks.
Posted

Wonderful example can be found here

Limit the Number of Characters in a Textarea or Text Field

or you can even try modifying code by replacing MaxLength with maxlength
 
Share this answer
 
v3
remove the property, TextMode="MultiLine"

XML
<asp:TextBox ID="TextBox3" runat="server"  MaxLength="100"
 OnTextChanged="TextBox3_TextChanged" Font-Size="Medium"
           style="z-index: 1; left: 930px; top: 178px; position: absolute;height: 40px; width: 225px"></asp:TextBox>


if you want to use multiline check no of characters on submit using
TextBox3.Text.Length

or use regular expression validator for text box3 and use regular expression : (\s|.){0,10}$

as follows

XML
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
        ControlToValidate="TextBox3" ErrorMessage="RegularExpressionValidator"
        ValidationExpression="(\s|.){0,10}$"></asp:RegularExpressionValidator>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900