Solved

limit the asp:text control to 10 number of characters

Posted on 2006-11-17
6
2,547 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

690 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