Control控件呈现过程中3个重要的方法,实现大抵如下:
public virtual void RenderControl(HtmlTextWriter writer)
{
if (Visible)
Render(writer);
}
public virtual void Render(HtmlTextWriter writer)
{
// render itself
// todo...
// render children
RenderChildren(writer);
}
public virtual void RenderChildren(HtmlTextWriter writer)
{
foreach (Control item in this.Controls)
item.RenderControl(writer);
}
所以,一般情况下,我们无须重写RenderControl方法和RenderChildren方法,最合适的就是重写Render方法。