When the textmode of textbox is set to multiline, its maxlength does not work. Solution _ 1

Source: Internet
Author: User
When the textmode of textbox is set to multiline, its maxlength does not work. Solution _ 1


Release date: 2009/5/7 20:16:23 Popularity Index: 74

Non-continuous reading | publish news | comment | stick | print


Method 1: Verify the control (practical)

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 = "more than 200 words" validationexpression = "^ [\ s] {0,200} $" runat = "server"/>

 

Method 2: a dialog box is displayed.
1.html code

<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: Running PX" runat = "server"
Textmode = "multiline" Height = "pixel PX" width = "271px"> </ASP: textbox>
</Form>
</Body>
</Html> 2. CS code
Private void page_load (Object sender, system. eventargs E)
{
This.txt name. Attributes. Add ("onblur", "isover (this, 1000 );");
}
Method 3: Custom Controls
Multiline textbox with maxlength Validation
Http://www.codeproject.com/KB/aspnet/Textarea_Length_Validator.aspx

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.