?
Solved

limit the asp:text control to 10 number of characters

Posted on 2006-11-17
6
Medium Priority
?
2,551 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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.…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

777 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