asp.net textbox techniques using _ Practical Tips

Source: Internet
Author: User

①, when you are doing web development, you may also encounter problems that I have encountered before, when using a TextBox control, the edge of the control cannot be completely overwritten by the background picture, as shown in Figure 1:

Because the TextBox parsing is also the Html-text control, and the text control is the default side, that is, the border:1px solid #000;

So as long as the TextBox control plus the following a small sentence of CSS can be, that is, "border:0px", the final effect as shown in Figure 2:

②, everyone in doing web development, do not know if we have found, when the TextBox control TextMode = "MultiLine", in fact, MaxLength has been invalidated.

Because the TextBox's property is TextMode to "MultiLine", after parsing is the Html-textarea control, the HTML control has no maxlength attribute.

If you want to limit its input length at this point: you can set the following properties:

<asp:textbox ID = "reply_note" runat = "server" TextMode = "MultiLine" onkeyup= "this.value " = This.value.slice (0, 10 ) ">

③, when you do some input boxes, you may want to do when the focus of the trigger an event, when the failure to trigger an event:

I wrote two JS just to meet the following effects:

Copy Code code as follows:

<script type= "Text/javascript" >
Trigger event when focus is received
function Onfocusfun (element, Elementvalue) {
if (Element.value = = Elementvalue) {
Element.value = "";
Element.style.color = "";
}
}

Trigger event when leaving input box
function Onblurfun (element, Elementvalue) {
if (Element.value = = "") {
Element.style.color = "#808080";
Element.value = Elementvalue;
}
}
</script>

Then, you can refer to them in the TextBox control as follows:
Copy Code code as follows:

<asp:textbox ID = "reply_note" runat = "text=" Post reply, input Word limit of 1000 words "ForeColor =" #808080 "onfocus=" Onfocusfun (thi S, ' post reply, input Word limit of 1000 words ')
Onblur= "Onblurfun (this, ' post reply, input Word limit of 1000 words ')" ></asp:TextBox>

This is my recent development of a little bit of skill, may have been written on the internet similar, but these methods, I personally think is relatively simple and understandable, hope to help everyone.

If you have other similar tips, you can leave a message to share.

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.