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

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 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.

Method 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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x