Strange HTML control textarea

Source: Internet
Author: User

Although I have never used the HTML control textarea, according to my own style, lou pig boldly believes that the textmode of the textarea and Server Control textbox is multiline and should be the same on the final HTML Tag. Maybe it's preemptible. In a design page last week, Lou pig wrote the following HTML without thinking.Code:

< Textarea ID = "Txttest1" Value = "123" Cols = "20" Rows = "2" > </ Textarea >

Then, VS has a prompt:Message 1 verification (XHTML 1.0 transitional): the attribute "value" is not a valid attribute of the element "textarea.
Dizzy, does textare have no value attribute? Then Lou pig tries to put textarea on the server:

< Textarea ID = "Txttest1" Cols = "20" Rows = "2" Enableviewstate = "False" Runat = "Server" > </ Textarea >

Then, in the CS file, you can write the following code:

This . Txttest1.value =   " 123 " ;

This indicates that the value attribute of the server exists. Lou pig checked the Value Attribute metadata description to obtain or set the text entered in the system. Web. UI. htmlcontrols. htmltextarea control. Check the generated HTML source code:

< Textarea name = " Txttest1 " ID = " Txttest1 " Cols = " 20 " Rows = " 2 " > 123 </ Textarea >

It is clear now. The original "value" value of textarea is in the start and end labels of textarea, rather than the input with the text type. It seems that the value is placed on the value attribute. Lou pig then used the Server Control textbox and runat as the server's textarea for a comparison:


< ASP: textbox ID = "Txttest" Textmode = "Multiline" Enableviewstate = "False" Runat = "Server" > </ ASP: textbox >
< Textarea ID = "Txttest1" Cols = "20" Rows = "2" Enableviewstate = "False" Runat = "Server" > </ Textarea >

Write the following code in Cs:

This . Txttest. Text =   " 123 " ;
This . Txttest1.value =   " 123 " ;

They generate the same HTML:

< Textarea Name = "Txttest" Rows = "2" Cols = "20" ID = "Txttest" > 123 </ Textarea >
< Textarea Name = "Txttest1" ID = "Txttest1" Cols = "20" Rows = "2" > 123 </ Textarea >

For Textbox, it can directly write the text attribute on the tag, but the textarea of runat = "server" cannot directly write the value attribute in the tag:

< ASP: textbox ID = "Txttest" Textmode = "Multiline" Text = "123" Enableviewstate = "False" Runat = "Server" > </ ASP: textbox >

Then, Lou pig uses JavaScript to obtain their values:

VaR Txtvalue = Document. getelementbyid ( " Txttest " ). Value;
Alert (txtvalue );
VaR Txtvalue1 = Document. getelementbyid ( " Txttest1 " ). Value;
Alert (txtvalue1 );

Kao. The value 123 is displayed this time! This indicates thatTextarea has the value attribute.(The same is true for innertext ). It's really complete. At last, Lou pig switched textarea to a textbox without a view state that he had been using for the sake of insurance, because he is not familiar with it and cannot understand the odd Design of textarea. Looking forward to your guidance.

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: 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.