Literal控件与TextBox控件结合的自定义复合控件

作者:网络 来源:佚名 更新时间:2008-02-05 16:16:01 点击:
本控件主要解决了自定义复合控件中,客户端验证脚本。
using system;
using system.web;
using system.web.ui;
using system.web.ui.webcontrols;
using system.componentmodel;

namespace only.compositioncontrols
{
/// <summary>
/// create by liyi。
/// date:2004-10-10
/// </summary>
[defaultproperty("value"),validationpropertyattribute("value"),toolboxdata("<{0}:literaltextbox runat=server></{0}:literaltextbox>")]
public class literaltextbox:control,inamingcontainer
{
//以下脚本用于从文本框输入页码
[defaultvalue("text:"),category("自定义")]
public string text
{
get
{
this.ensurechildcontrols();
return ((literalcontrol)controls[0]).text;
}
set
{
this.ensurechildcontrols();
((literalcontrol)controls[0]).text = value;
}
}
[defaultvalue("value"),category("自定义")]
public string value
{
get
{
this.ensurechildcontrols();
return ((textbox)controls[1]).text;
}
set
{
this.ensurechildcontrols();
((textbox)controls[1]).text = value;
}
}
[defaultvalue(""),category("自定义")]
public unit width
{
get
{
this.ensurechildcontrols();
return ((textbox)controls[1]).width;
}
set
{
this.ensurechildcontrols();
((textbox)controls[1]).width = value;
}
}
[defaultvalue(textboxmode.singleline),category("自定义")]
public textboxmode textmode
{
get
{
this.ensurechildcontrols();
return ((textbox)controls[1]).textmode;
}
set
{
this.ensurechildcontrols();
((textbox)controls[1]).textmode = value;
}
}
[defaultvalue(borderstyle.notset),category("自定义")]
public borderstyle borderstyle
{
get
{
this.ensurechildcontrols();
return ((textbox)controls[1]).borderstyle;
}
set
{
this.ensurechildcontrols();
((textbox)controls[1]).borderstyle = value;
}
}
[defaultvalue(""),category("自定义")]
public unit borderwidth
{
get
{
this.ensurechildcontrols();
return ((textbox)controls[1]).borderwidth;
}
set
{
this.ensurechildcontrols();
((textbox)controls[1]).borderwidth = value;
}
}
protected override void createchildcontrols()
{
this.controls.add(new literalcontrol("text:"));

textbox box = new textbox();
box.text = "value";
box.id = "only";
this.controls.add(box);
}
}
}