Textbox.maxlength Property
Gets or sets the maximum number of characters allowed in the text box
The maximum number of characters allowed in the text box. The default value is 0, which indicates that the property is not set.
Use the MaxLength property to qualify the number of characters that can be entered in a TextBox control.
Note: This property applies only when the TextMode property is set to TextBoxMode.SingleLine or Textboxmode.password.
MaxLength Invalid problem with textbox
Method One: Verify the control (as practical as possible)
validation controls
Code to copy code as follows
<asp:textbox id= "Txtconclusion" maxlength= "$" textmode= "MultiLine" height= "100px" width= "400px" runat= "Server"/ >
<asp:regularexpressionvalidator id= "TxtConclusionValidator1" controltovalidate= "txtconclusion" text= "more than 200 words" validationexpression= "^[ss]{0,200}$" runat= "Server"/>
Method Two: Add some client-bound JS code. Examples are as follows:
Code
Code to copy code as follows
<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.c (www.111cn.net) om/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>
public void Page_Load (object sender, System.EventArgs e)
{
THIS.TXTNAME.ATTRIBUTES.ADD ("onblur", "Isover (this,1000);");
}
From:http://www.111cn.net/net/160/66645.htm
Example of C # textbox.maxlength in ASP.