Asp.net-textbox tips

Source: Internet
Author: User

① During web development, you may also encounter problems that I encountered before. When using the Textbox Control, the edge of the control cannot be completely overwritten by the background image. 1:

After textbox resolution, it is also an HTML-text control, while the text control has edges by default, that is, border: 1px solid #000;

Therefore, you only need to add the following small CSS for the Textbox Control, that is, "border: 0px", and the final effect is 2:

 

② When you are doing web development, I wonder if you have found that when textmode = "multiline" of the Textbox Control is replaced, maxlength has actually expired.

When the textmode attribute of textbox is "multiline", it is actually the HTML-textarea control after parsing. This html control does not have the maxlength attribute.

If you want to limit the input length, you can set the following attributes:

<Asp: textbox id = "reply_note" runat = "server" textmode = "multiline"Onkeyup = "This. value = This. value. Slice (0, 1000 )">

 

③ When you make some input boxes, you may want to trigger an event when you get the focus, or trigger an event when you lose focus:

I wrote two JS files to meet the following requirements:

   <  Script Type  =  "  Text/JavaScript  "  >  
// Event triggered when the focus is obtained
Function Onfocusfun (element, elementvalue ){
If (Element. Value = Elementvalue ){
Element. Value = "" ;
Element. style. Color = "" ;
}
}

// Triggered when the input box is left
Function Onblurfun (element, elementvalue ){
If (Element. Value = '' ){
Element. style. Color = " #808080 " ;
Element. Value = Elementvalue;
}
}
< / SCRIPT>

 

Then, you can reference them in the Textbox Control as follows:

 <  ASP: textbox ID  =     "  Reply_note  "  Runat  =    "  Server  "  Text  =  "  Post reply, up to 1000 words entered  "  Forecolor  =     "  #808080  "  Onfocus  =  " Onfocusfun (this, 'Post reply, up to 1000 words ')  " 
 
Onblur="Onblurfun (this, 'Post reply, up to 1000 words ')"> </ASP: textbox>
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.