Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?
like image 343
citronas Avatar asked Mar 10 '10 10:03

citronas


People also ask

What is the used of the MaxLength property in a TextBox?

The maxlength attribute defines the maximum number of characters (as UTF-16 code units) the user can enter into an <input> or <textarea> .

What is the default value of MaxLength property of text box control?

The maximum number of characters that can be manually entered into the text box. The default is 0, which indicates no limit.

Which property of the TextBox control is used to set the maximum length of the text that can be entered in a TextBox?

Use the MaxLength property to limit the number of characters that can be entered in the TextBox control.


2 Answers

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.

like image 107
Locksfree Avatar answered Sep 19 '22 19:09

Locksfree


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.

like image 43
Henk Holterman Avatar answered Sep 16 '22 19:09

Henk Holterman