Solved

limit the asp:text control to 10 number of characters

Posted on 2006-11-17
6
2,527 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
Comment Utility
Remove the multiline textmode...

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

Author Comment

by:shwaqar82
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 11

Expert Comment

by:Vivek Thangaswamy
Comment Utility
0
 
LVL 11

Expert Comment

by:ethoths
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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 …
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

21 Experts available now in Live!

Get 1:1 Help Now