How to set maxlength for multiline TextBox?

前端 未结 7 765
慢半拍i
慢半拍i 2020-12-16 01:51

When using a MultiLine TextBox (which generates a TextArea) setting the MaxLength property has no effect. What is the best workaround? I\'d like to get basic, intended funct

7条回答
  •  没有蜡笔的小新
    2020-12-16 02:14

    If you don't care about older browsers (see supported browsers here),
    you can set MaxLength normally like this

    
    

    and force it to be printed out to the HTML

    protected void Page_Load(object sender, EventArgs e)
    {
      if (!IsPostBack)
        txt1.Attributes.Add("maxlength", txt1.MaxLength.ToString());
    }
    

提交回复
热议问题