Asp.net limits the number of words in the text box and displays the remaining words

Source: Internet
Author: User

BelowCodeIt is directly copied from the vs2005 development environment. You can directly copy it and run it.
ThisProgramThere is still a problem when processing Chinese characters. it is limited to 120 characters and 60 Chinese characters, but it is possible that you can only enter 55 characters. It is strange that you are looking for the reason. it will be updated later. if you can see it, please help change it... thank you .....

<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default2.aspx. cs" inherits = "default2" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
<SCRIPT type = "text/JavaScript">
Function fucchecklength (strtemp)
{
VaR I, sum;
Sum = 0;
For (I = 0; I <strtemp. length; I ++)
{
If (strtemp. charcodeat (I)> = 0) & (strtemp. charcodeat (I) <= 255 ))
Sum = sum + 1;
Else
Sum = sum + 2;
}
Return sum;
}
Function showleft (){
VaR lenstring, lenstringi, strings;
Lenstring = fucchecklength (document. getelementbyid ("textbox1"). value );
Lenstringi = lenstring;
If (lenstring & gt; 120 ){
Alert ("the length of the entered characters cannot exceed 120 (60 Chinese characters )! ");
Strings = Document. getelementbyid ("textbox1"). value;
While (lenstringi> 120 ){
If (strings. charcodeat (strings. Length)> = 0) & (strings. charcodeat (strings. Length) <= 255 )){
Lenstringi = LenStringI-1;
}
Else {
Lenstringi = LenStringI-2;
}
Strings = strings. substring (0, (strings. Length-1 ));
}
Document. getelementbyid ("textbox1"). value = strings;
Return false;
}
Document. getelementbyid ("button1"). value = 250-lenstring;

}
</SCRIPT>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Asp: textbox id = "textbox1" runat = "server" Height = "156px" textmode = "multiline" width = "326px" onkeyup = "Return showleft (); "> </ASP: textbox>
<Input id = "button1" type = "button" value = "120"/>
</Div>
</Form>
</Body>
</Html>

Related Article

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.