我可以限制多行asp中的新行数:TextBox

时间:2015-06-15 08:26:05

标签: javascript c# asp.net

我可以使用javascript或C#

限制多行asp中的3个新行:TextBox

1 个答案:

答案 0 :(得分:-1)

只有将Rows属性设置为3才能达到以下目的:

<asp:TextBox ID="txtBox1" runat="server" Rows="3" TextMode="MultiLine"></asp:TextBox>

使用javascript:

function validate(e, max,maxchar)
{
var text = e.value.replace(/\s+$/g,""); var split = text.split("\n");
if (split.length <= max && text.length <=maxchar)
{
  return true;
}
else if (split.length >= max || e.value.length >=maxchar)
{
 return false;
}
}
 <asp:TextBox ID="txtBox1" runat="server" TextMode="MultiLine" Rows="3" onkeypress="return validate(this,max_number,maxchar_number)"/>

根据您的要求更改max_numbermaxchar_number的值。