Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

limit the asp:text control to 10 number of characters

Posted on 2006-11-17
6
Medium Priority
?
2,552 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

636 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