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