我有一个名为 DateTimeUC 的用户控件,它的标记上有两个文本框:
<asp:TextBox ID="dateTextBox" runat="server"></asp:TextBox>
<asp:TextBox ID="timeTextBox" runat="server"></asp:TextBox>
我在另一个用户控件中动态创建此控件:
Controls.Add(GenerateDateTime(parameter));
private DateTimeUC GenerateDateTime(SomeParameter parameter)
{
DateTimeUC uc = new DateTimeUC();
uc.ID = parameter.Name;
return uc;
}
但是当我渲染页面时,DateTimeUC 什么都不渲染。我是这样检查的:
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
StringBuilder builder = new StringBuilder();
StringWriter swriter = new StringWriter(builder);
HtmlTextWriter hwriter = new HtmlTextWriter(swriter);
base.Render(hwriter);
string s = builder.ToString();
}
s 为空,Controls.Count 为 0。我做错了什么?