我有一个名为UC_Widget的UserControl,它从System.Web.UI.UserControl和ITextControl继承。它也覆盖了AddParsedSubObject函数。当我像下面一样使用它时,它运行良好。如何将UserControl添加到其他UserControl?
<uc1:UC_Widget ID="UC_Widget1" runat="server">
hello world
</uc1:UC_Widget>
但是,它出来一个问题:如果我想使用此控件包含另一个用户控件, 如何为这个做?许多thx!
<uc1:UC_Widget ID="UC_Widget1" runat="server">
hello world
<uc1:UC_Widget ID="UC_Widget2" runat="server">
guy
</uc1:UC_Widget>
</uc1:UC_Widget>
thx Nix,我已经通过AddParsedSubObject方法解决了这个问题。
protected override void AddParsedSubObject(object obj)
{
if (this.HasControls())
{
base.AddParsedSubObject(obj);
}
else if (obj is LiteralControl)
{
HtmlContent.Append(((LiteralControl)obj).Text);
this.Text = HtmlContent.ToString();
}
else
{
string text1 = this.Text;
UC_eClinicWidget tmp = obj as UC_eClinicWidget;
if (tmp != null)
{
HtmlContent.Append(GetControlHtml(tmp));
this.Text = HtmlContent.ToString();
}
}
}
你得到了什么错误? – Nix 2010-09-02 12:27:06
Thx Nix,我得到这个错误,控件集合不能被修改,因为控件包含代码块(即<% ... %>)。 而我执行AddParsedSubObject方法 – 2010-09-03 01:26:48