ASP.NET Render 概要

在ASP.NET的生命周期走到Render阶段,Page.ProcessMain方法会调用Page的RenderControl方法,RenderControl方法会调用RenderControlInternal,RenderControlInternal根据该空间否是有ControlAdapter调用不同的呈现方法。RenderControlInternal的方法原型如下:

    private void RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
    {
      
if (adapter != null)
      {
        adapter.BeginRender(writer);
        adapter.Render(writer);
        adapter.EndRender(writer);
      }
      
else
      {
        
this.Render(writer);
      }
    }

 

默认情况下会执行到Page类的Render方法。

 剩下的过程如下:

Page.Render--->Control.Render--->Control.RenderChildren--->Control.RenderChildrenInternal --->control.RenderControl--->Control.RenderControlInternal.

 

RenderChildrenInternal的方法原型如下: 

     internal void RenderChildrenInternal(HtmlTextWriter writer, ICollection children)

    {
      
if ((this.RareFields != null&& (this.RareFields.RenderMethod != null))
      {
        writer.BeginRender();
        
this.RareFields.RenderMethod(writer, this);
        writer.EndRender();
      }
      
else if (children != null)
      {
        
foreach (Control control in children)
        {
          control.RenderControl(writer);
        }
      }
    }

Remark:

In the method of  RenderChildrenInternal,the argument children with type IConllection will be circulated,to invoke t every control's RenderControl Method.

posted @ 2011-05-20 08:03  cnbwang  阅读(1243)  评论(3编辑  收藏  举报