How reliable is the MaxLength property of the TextBox-Control?

柔情痞子 提交于 2019-11-30 05:32:55

问题


The TextBox control offers a MaxLength property, which allows the insertable text into that TextBox be clientside limited to the specified amount of chars.

My questions:

  • Is this property only client-side and therefore browser-pedendent?
  • Can I rely on the fact, that the Text property contains no text longer than MaxLength is set (only for the DisplayModes named in the MSDN article) or do I manually have to perform a TextBox.Text.SubString(0, DesiredMaxLength) ?
  • How does all this behave with disabled java-script?

回答1:


It does not depend on javascript but that does not make it safe.

Anyone can still post a request using javascript (XmlHttpRequest for example) or just craft a request to send more data than the max-length specification. It's a good way to stop a normal user from over populating a field but it is something you need to double check on the server anyway.




回答2:


Can I rely on the fact, that the Text property contains no text longer than MaxLength ?

No. Consider it a user-friendliness feature. You will have(as always) re-check on the server. And maybe also check in JavaScript, depending on what its for.



来源:https://stackoverflow.com/questions/2416242/how-reliable-is-the-maxlength-property-of-the-textbox-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!