Asp.net文本框,Multiline属性为true,不支持max lenght值,为什么?

时间:2021-04-05 00:58:29

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.

奇怪的是,具有多行属性的Asp.net文本框不支持max lenth属性。我们需要通过编写自定义的java脚本代码来管理它。

2 个解决方案

#1


1  

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

因为textbox-mode多线渲染为textarea,而textarea不包含maxlength属性。

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

是的,应用一个JavaScript,并确保添加一些服务器端检查的长度(如果客户端禁用JavaScript)

#2


0  

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

TextBox,当多行时,呈现不包含MaxLength属性的TextArea。

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.

TextBox控件的行为应与MaxLength属性的输出不同,具体取决于TextMode属性。如果它是单行,则渲染MaxLength,如果不是,则渲染JavaScript。我认为这是一个不好的行为或可能是一个错误。

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

在这些情况下,当您感到好奇时,您总是可以使用Reflector查看Microsoft的代码。

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

这是AddAttributesToRender方法中MaxLength属性呈现的代码片段:

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

#1


1  

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

因为textbox-mode多线渲染为textarea,而textarea不包含maxlength属性。

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

是的,应用一个JavaScript,并确保添加一些服务器端检查的长度(如果客户端禁用JavaScript)

#2


0  

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

TextBox,当多行时,呈现不包含MaxLength属性的TextArea。

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.

TextBox控件的行为应与MaxLength属性的输出不同,具体取决于TextMode属性。如果它是单行,则渲染MaxLength,如果不是,则渲染JavaScript。我认为这是一个不好的行为或可能是一个错误。

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

在这些情况下,当您感到好奇时,您总是可以使用Reflector查看Microsoft的代码。

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

这是AddAttributesToRender方法中MaxLength属性呈现的代码片段:

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