Use ASP. Net Atlas to develop a textarea that automatically adjusts the number of lines with the input content

Source: Internet
Author: User
Author:Dflying Chen (http://dflying.cnblogs.com)

Used by many friends Outlook Or Windows Live Mail: When writing a new email, you will find that the initial recipient text box contains only one line. However, if you enter a lot of addresses that exceed the length of a row, it will automatically become two rows. If not, it will also become three or four rows. This text box not only saves the initial space, but also makes it difficult for users to enter a large amount of data. To give you a more intuitive understanding of the above products, or some friends have not used the above products, please refer to the following:

Initially, there are only two rows:
When you continue to input, the number of rows will automatically increase:

When it is increased to the set maximum number (here is5,
The scroll bar will still appear:

If you delete some of the text,
The number of rows will also be automatically reduced:

How are you doing? If you are usingASP. NET AtlasTo implement this function, you only need to create an input control:Autoresizetextarea

    1. Make full useAtlasPowerfulJavascriptThe object-oriented function inherits fromSYS. UI. textboxClass, reuse the basic functions of the parent class.
    2. CaptureDomOfOnkeyupEvent, and determine whether the event exceeded thisTextareaThe number of characters that can be accommodated to dynamically adjustTextareaThe number of rows. This is a part of the control implementation that has "technical content". You can refer to the source file to obtain the specific implementation.

AutoresizetextareaThere are two attributes:

    1. Minrowcount:TextareaThe minimum number of rows, default value andTextareaDeclaredRowsThe property is the same, ifTextareaNo declarationRowsThe default value is3.
    2. Maxrowcount:TextareaThe maximum number of rows. The default value is7.

Here you can easily expand or override my logic, for exampleMaxrowcountThe default value of the attribute is changed to infinity.

UseAutoresizetextareaNote the following:

    1. ScriptmanagerTo addAutoresizetextarea. jsFile reference.
    2. AsAutoresizetextareaControl SourceDomThe element must beTextarea, MyCodeDoes not check related elements. You can easily add them if needed.

Source Code of the control and Program download here: http://files.cnblogs.com/dflying/AutoResizeTextArea.zip

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.