Example of C # textbox.maxlength in ASP.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.