Shyam
Shyam

Reputation: 21

Asp.net text Box ,with Multiline attribute true does not support max lenght value, why?

It is strange Asp.net Text box with multi line attribute does not support max lenth property. we need to manage it by writing customized java script Code.

Upvotes: 0

Views: 773

Answers (2)

Andre Pena
Andre Pena

Reputation: 59336

TextBox, when multi-line, renders a TextArea that does not contain a MaxLength property.

TextBox control should act different as for the output of the MaxLength property depending on the TextMode property. If it's single-line, render MaxLength, if it's not, render a JavaScript. I consider it a bad behavior or maybe a bug.

In these cases when you are curious you can always take a look at Microsoft's code with Reflector.

Here's the code snippet for MaxLength property rendering in the AddAttributesToRender method:

int maxLength = this.MaxLength;
    if (maxLength > 0)
    {
        writer.AddAttribute(HtmlTextWriterAttribute.Maxlength, maxLength.ToString(NumberFormatInfo.InvariantInfo));
    }
    maxLength = this.Columns;
    if (maxLength > 0)
    {
        writer.AddAttribute(HtmlTextWriterAttribute.Size, maxLength.ToString(NumberFormatInfo.InvariantInfo));
    }

Upvotes: 0

karlis
karlis

Reputation: 920

because the textbox-mode multiline is rendered as textarea, and the textarea does not contain a maxlength property.

yes, apply a javascript, and, to be sure add also some server-side check for the length (if the client disables javascript)

Upvotes: 1

Related Questions