Specifying maxlength for multiline textbox

后端 未结 19 2112
感动是毒
感动是毒 2020-11-27 15:21

I\'m trying to use asp:


I want a way to spe

19条回答
  •  甜味超标
    2020-11-27 16:19

    Another way of fixing this for those browsers (Firefox, Chrome, Safari) that support maxlength on textareas (HTML5) without javascript is to derive a subclass of the System.Web.UI.WebControls.TextBox class and override the Render method. Then in the overridden method add the maxlength attribute before rendering as normal.

    protected override void Render(HtmlTextWriter writer)
    {
        if (this.TextMode == TextBoxMode.MultiLine
            && this.MaxLength > 0)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Maxlength, this.MaxLength.ToString());
        }
    
        base.Render(writer);
    }
    

提交回复
热议问题