When using a MultiLine TextBox (which generates a TextArea) setting the MaxLength property has no effect. What is the best workaround? I'd like to get basic, intended functionality with minimum of ugly javascript etc. Just prevent user from entering more than max number of characters.
相关问题
- Carriage Return (ASCII chr 13) is missing from tex
- How to store image outside of the website's ro
- 'System.Threading.ThreadAbortException' in
- Request.PathInfo issues and XSS attacks
- How to dynamically load partial view Via jquery aj
相关文章
- asp.net HiddenField控件扩展问题
- asp.net HiddenField控件扩展问题
- Asp.Net网站无法写入错误日志,测试站点可以,正是站点不行
- asp.net mvc 重定向到vue hash字符串丢失
- FormsAuthenticationTicket expires too soon
- “Dynamic operations can only be performed in homog
- What is the best way to create a lock from a web a
- Add to htmlAttributes for custom ActionLink helper
Hey pukipuki you can do as follows:
You can see more in this following link: http://jquerybyexample.blogspot.in/2010/10/set-max-length-for-aspnet-multiline.html
If you don't care about older browsers (see supported browsers here),
you can set MaxLength normally like this
and force it to be printed out to the HTML
To force asp.net to send the maxlength attribute for all multiline textboxes on a page or a whole site, building on Aximili's answer above:
I use the control extension method from David Findley https://weblogs.asp.net/dfindley/linq-the-uber-findcontrol and referenced in this SO post Loop through all controls on asp.net webpage
Make sure to reference the namespace for the extension method in step 1.
Put the following code in the Page_Load function:
Try this..
Here's a cross browser solution :
Javascript :
You have to think about the Copy and Paste. This is a little bit tricky, I simply disable it with Jquery. But you can create your own function to do more complex verification. But in my case, copy and paste is not allowed.
Jquery to disable copy and paste :
If you want to let the user know if he exceeded the amount of characters as he writes, you could use a javascript function attached to keypress event. This function would test the length of the input and cancel the character rendering if the maxlenght was reached.
Another option is to use
RegularExpressionValidator
control to validate the input on submit.In my opinion, the first option is much more better.
I'm not adding any code since google is full of examples for all tastes, this is a very common task.
Here you have a sample search that might help.