ASP.net 自定义服务器控件 TextBox
2010-01-11 19:29
387 查看
基于项目需要,针对ASP.net服务器控件TextBox进行改造,使其增加字符串输入提示功能,在控件获得焦点时,与普通的服务器端TextBox控件相同,支持数据输入。当控件失去焦点并且文本框内容为空时,显示预定义的提示文本。用户输入“预定义的提示文本”为文本内容时,默认文本框Text值为空字符串。
[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);
}
}本文出自 “学习成就梦想” 博客,请务必保留此出处http://qijinchao.blog.51cto.com/1140455/263627
[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);
}
}本文出自 “学习成就梦想” 博客,请务必保留此出处http://qijinchao.blog.51cto.com/1140455/263627
相关文章推荐
- ASP.NET自定义Web服务器控件-TextBox文本框控件
- ASP.NET - 如何:使用自定义函数对 ASP.NET 服务器控件进行验证
- asp.net textbox等服务器控件包含html代码的时候,提交会报错
- ASP.NET自定义Web服务器控件-登录控件
- Asp.net自定义服务器控件开发小技巧: 如何正确获得回传数据
- ASP.NET 2.0中TextBox服务器控件的ReadOnly和Disabled属性
- ASP.NET 2.0中TextBox服务器控件的ReadOnly和Disabled属性
- asp.NET自定义服务器控件内部细节系列教程六(复杂属性)
- ASP.NET自定义Web服务器控件-DropDownList/Select下拉列表控件
- 关于form表单中禁用所有Asp.net 服务器控件TextBox的方法
- ASP.NET自定义服务器控件
- ASP.NET 2.0中TextBox服务器控件的ReadOnly和Disabled属性
- ASP.NET中保护自定义的服务器控件
- asp.net 自定义服务器控件属性
- asp.net Textbox服务器控件
- asp.net 自定义服务器控件标签属性解释
- 100%托管代码自定义服务器控件ASP.NET Barcode Web Server Control
- ASP.net 自定义服务器控件之 GridViewControl
- ASP.NET 2.0中TextBox服务器控件的ReadOnly和Disabled属性
- Asp.net中TextBox控件内容更改后无法POST到服务器