方法一: 验证控件验证(经实践可行)
setting the maxength of a textbox when it is in multiline, you can use regularexpressionvalidator control as shown below
<asp:textbox id="txtconclusion" maxlength="200" textmode="multiline" height="100px" width="400px" runat="server" />
<asp:regularexpressionvalidator
id="txtconclusionvalidator1" controltovalidate="txtconclusion"text="超过200字" validationexpression="^[\s\s]{0,200}$"
runat="server" />
方法二:弹出对话框提示
1.html代码
<html>
<head>
<title>webform6</title>
<meta name="generator" content="microsoft visual studio .net 7.1">
<meta name="code_language" content="c#">
<meta name="vs_defaultclientscript" content="javascript">
<meta name="vs_targetschema" content="http://schemas.microsoft.com/intellisense/ie5">
<script language="javascript">
function isover(stext,len)
{
var intlen=stext.value.length;
if (intlen>len)
alert("the content length must less than or equal "+len);
stext.focus();
stext.select();
}
}
</script>
</head>
<body ms_positioning="gridlayout">
<form id="form1" method="post" runat="server">
<asp:textbox id="txtname" style="z-index: 102; left: 200px; position: absolute; top: 104px" runat="server"
textmode="multiline" height="112px" width="271px"></asp:textbox>
</form>
</body>
</html>
2.cs代码
private void page_load(object sender, system.eventargs e)
this.txtname.attributes.add("onblur","isover(this,1000);");
}
方法三: 自定义控件
multiline textbox with maxlength validation
http://www.codeproject.com/kb/aspnet/textarea_length_validator.aspx