asp.net Custom server control textbox

Source: Internet
Author: User

The

is modified for the ASP.net server control textbox to add a string input hint based on project needs, which, when the control has the focus, supports data entry, the same as a normal server-side TextBox control. Displays a predefined hint text when the control loses focus and the text box contents are empty. When the user enters "predefined hint text" as text content, the default text box text value is an empty string.

[Defaultproperty ("Text")]
[ToolBoxData ("<{0}:textbox runat=server></{0}:textbox>")]
public class TextBox:System.Web.UI.WebControls.TextBox
{
[bindable (True)]
[Category ("appearance")]
[DefaultValue (")]
[Localizable (true)]
[Browsable (true)]
public string Tip
{             
Get
{
String s = (string) viewstate["Tip"];
 Return ((s = = null)? STRING.EMPTY:S);         
}
Set
{
viewstate["Tip"] = value;

}
[Bindable (True)]
[Category ("appearance")]
[DefaultValue ("")]
[localizable (true)]
public override string Text
{
Get
{
if (base. Text.tolower () = = Tip.tolower ())
return string. Empty;
return base. Text;
}
Set
{
base. Text = value;
}
}
protected override void Render (HtmlTextWriter writer)
{
this. Attributes.Add ("Tip", tip);
this. Attributes.Add ("onblur",
"if (this.value== ')" {this.style.color= ' #C1C1C1 '; this.value= ' "+tip+" ';}; ");
this. Attributes.Add ("onfocus",
"if" (this.value== ' +tip+ "') {this.style.color= ' #000000 '; this.value= ';};");
if (string. IsNullOrEmpty (base. Text.trim ())
{
this. Attributes.Add ("value", this. TIP);
this. Attributes.Add ("Style", "Color: #C1C1C1");
}
Base. Render (writer);
}
}

This article is from the "Learning Achievement Dream" blog, please be sure to keep this source http://qijinchao.blog.51cto.com/1140455/263627

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.