How to set maxlength for multiline TextBox?

2020-02-09 10:19发布

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.

7条回答
乱世女痞
2楼-- · 2020-02-09 11:18

If you are using a model object bind to that textbox you can use DataAnnotations attributes to set the maxlength of that property. I'm based on MVC about that but it should work for ASP.NET too!

This way you don't mess with any Javascript or setting anything in the markup.

查看更多
登录 后发表回答