开发者

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

开发者 https://www.devze.com 2022-12-16 10:57 出处:网络
It is strange Asp.net Text box with multi line attribute do开发者_开发技巧es not support max lenth property.

It is strange Asp.net Text box with multi line attribute do开发者_开发技巧es not support max lenth property. we need to manage it by writing customized java script Code.


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)


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));
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消