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 |