我想构建一个继承自System.Web.UI.WebControls.MultiView的服务器控件。
该控件将包含一组服务器控件,这些控件依次从System.Web.UI.WebControls.View继承。但是,当我向控件的View集合添加单个视图时,不会呈现任何内容......
public class WizardMultiview : System.Web.UI.WebControls.MultiView
{
// field
private WizardStart _start;
override CreateChildControls()
{
this._start = new WizardStart(); // custom view
this._start.ID = "WizardStart1";
this.Views.Add(this._start);
this.ActiveViewIndex = 0;
}
override Render(HtmlTextWriter writer)
{
// NOTE: at this point the control can't render itself.
}
}
然后,在Default.aspx.cs中我做:
public void Page_Load(object sender, EventArgs e)
{
My.Controls.WizardMultiview view = new My.Controls.WizardMultiview();
this.Panel1.Controls.Add(view); // this is a Panel on the Default.aspx page
}
自定义View控件如下所示:
public class WizardStart : System.Web.UI.WebControls.View
{
override Render(HtmlTextWriter writer)
{
writer.WriteLine("I am the starting point");
}
}
当我将此控件添加到ASPX页面时,没有任何反应。但是,如果我创建一个MultiView,并将MultiView添加到CompositeControl的Control Collection并将视图添加到此MultiView,它可以正常工作吗?我确定我想要实现的目标是什么?