Solved

limit the asp:text control to 10 number of characters

Posted on 2006-11-17
6
2,534 Views
Last Modified: 2011-08-18
im trying to restrict asp text control that allow user to type on 10 characters by using the below html code:

<asp:textbox runat="server" textmode="multiline" id="txtinput" maxlength="10"></asp:textbox>

but when im filling the text box ..it allows me to enter more than 10 characters

How can i fix this
0
Comment
Question by:shwaqar82
6 Comments
 
LVL 11

Expert Comment

by:ethoths
ID: 17965968
Remove the multiline textmode...

<asp:textbox runat="server" id="txtinput" maxlength="10"></asp:textbox>
0
 

Author Comment

by:shwaqar82
ID: 17966117
well its comment box it should be 250 characters long ....thats why i put multiline mode..........is there any other way i can fix it
0
 
LVL 11

Expert Comment

by:Vivek Thangaswamy
ID: 17966142
Rememebr "Maxlength" property is not valid for multiline textbox mode. This property is only applicable when the TextMode property is set to TextBoxMode.SingleLine or TextBoxMode.Password.

ASP.NET Control
<asp:textbox runat="server" id="txtinput" maxlength="10"></asp:textbox>

HTML Element
<input type="text" maxlength="10">


0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 11

Expert Comment

by:Vivek Thangaswamy
ID: 17966168
0
 
LVL 11

Expert Comment

by:ethoths
ID: 17966211
If your 10 was a mistak ethen  try this...

http://www.cs.tut.fi/~jkorpela/forms/textarea.html

It's a full discussion on all th eoptions for text boxes and limiting theior size.
0
 
LVL 35

Accepted Solution

by:
mrichmon earned 250 total points
ID: 17966491
You can't limit it in .NET alone (you could adding javascript code to remove any excess characters as they are typed)
But you can validate the length in .NET - simply add a regular expression validator like this:

<asp:textbox runat="server" textmode="multiline" id="txtinput"></asp:textbox>
<asp:RegularExpressionValidator ID="txtinput_max" ControlToValidate="txtinput" validationexpression="(.|\r|\n){1,250}" Display="Dynamic" ErrorMessage="* Please enter maximum of 250 characters" Runat="server" />

This will limit to 250 characters.

If you don't want newlines allowed then remove the \r\n and just use:
validationexpression=".{1,80}"

(For example to add a validator to a regular input length - since validators check server side as well :o)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Send secure, cloud-based, encrypted alerts and maintain HIPAA compliant messaging. Integrates priority & secure messaging into one application. Ensures IT, emergency respondents and healthcare professionals that their critical messages are never mis…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now