是的,您将能够做到这一点。只需从类接口继承您的控件CompositeControl
,并将任何扩展程序或控件从 ACT 项目添加到 Controls 集合,就像您应该使用序号 ASP.NET 服务器控件执行此操作一样。您也可以继承现有的控件并实现INamingContainer
接口,但在这种情况下,您必须RenderChildren
从控件的方法中手动调用Render
方法:
[DefaultProperty("Text")]
[ToolboxData("<{0}:WatermarkedTextBox runat=server></{0}:WatermarkedTextBox>")]
public class WatermarkedTextBox : TextBox, INamingContainer
{
private AjaxControlToolkit.TextBoxWatermarkExtender _watermarkExtender;
public string WatermarkText
{
get
{
return ViewState["WatermarkText"] as string;
}
set
{
ViewState["WatermarkText"] = value;
}
}
protected override void CreateChildControls()
{
Controls.Clear();
this._watermarkExtender = new AjaxControlToolkit.TextBoxWatermarkExtender
{
ID = "wte",
TargetControlID = this.ID,
WatermarkText = this.WatermarkText
};
this.Controls.Add(_watermarkExtender);
}
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
RenderChildren(writer);
}
}
}