Asp. NET text disappears when text box (Texbox control) has text in focus when page loads

Source: Internet
Author: User

The code is as follows:

<asp:textbox id= "TextBox1" runat= "Server" height= "26px" maxlength= "ten" width= "166px" text= "Please enter user name" onfocus= " Javascript:if (this.value== ' Please enter user name ') {this.value= '; this.style.color= ' #000000 '} ' onblur= ' Javascript:if (this.value = = ') {this.value= ' Please enter user name '; this.style.color= ' #808080 '} ' forecolor= ' #808080 > </asp:TextBox>

  

Analytical:

1 · What the text box displays when the page loads

2 • After the text box triggers the focus, empty the text in the box and change the font color (you can also add formatting)

3 • After the focus leaves, determine if there is content in the text box, and no content restores the original font and formatting

4 · The color of the font in the text box when the page loads

Password Box code:
<asp:textbox id= "TextBox2" runat= "Server" height= "26px" width= "166px" text= "only a combination of numbers or letters" onfocus= "Javascript:if" ( this.value== ' Only a combination of numbers or letters ') {this.value= '; this.style.color= ' #000000 '; this.type= ' password '} "onblur=" Javascript:if (this.value== ") {this.type = ' text '; this.value= ' is only a combination of numbers or letters '; This.style.color= ' #808080 '} "forecolor=" #808080 "></asp:textbox >

  

  

Asp. NET text disappears when text box (Texbox control) has text in focus when page loads

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.