Control.RenderControl Control.RenderControl Control.RenderControl Control.RenderControl Method

定义

输出服务器控件内容,并存储有关此控件的跟踪信息(如果已启用跟踪)。Outputs server control content and stores tracing information about the control if tracing is enabled.

重载

RenderControl(HtmlTextWriter) RenderControl(HtmlTextWriter) RenderControl(HtmlTextWriter) RenderControl(HtmlTextWriter)

将服务器控件内容输出到所提供的 HtmlTextWriter 对象,如果启用了跟踪,则还将存储有关该控件的跟踪信息。Outputs server control content to a provided HtmlTextWriter object and stores tracing information about the control if tracing is enabled.

RenderControl(HtmlTextWriter, ControlAdapter) RenderControl(HtmlTextWriter, ControlAdapter) RenderControl(HtmlTextWriter, ControlAdapter) RenderControl(HtmlTextWriter, ControlAdapter)

使用提供的 HtmlTextWriter 对象将服务器控件内容输出到提供的 ControlAdapter 对象。Outputs server control content to a provided HtmlTextWriter object using a provided ControlAdapter object.

RenderControl(HtmlTextWriter) RenderControl(HtmlTextWriter) RenderControl(HtmlTextWriter) RenderControl(HtmlTextWriter)

将服务器控件内容输出到所提供的 HtmlTextWriter 对象,如果启用了跟踪,则还将存储有关该控件的跟踪信息。Outputs server control content to a provided HtmlTextWriter object and stores tracing information about the control if tracing is enabled.

public:
 virtual void RenderControl(System::Web::UI::HtmlTextWriter ^ writer);
public virtual void RenderControl (System.Web.UI.HtmlTextWriter writer);
abstract member RenderControl : System.Web.UI.HtmlTextWriter -> unit
override this.RenderControl : System.Web.UI.HtmlTextWriter -> unit
Public Overridable Sub RenderControl (writer As HtmlTextWriter)

参数

writer
HtmlTextWriter HtmlTextWriter HtmlTextWriter HtmlTextWriter

接收控件内容的 HtmlTextWriter 对象。The HtmlTextWriter object that receives the control content.

示例

下面的示例重写RenderChildren自定义服务器控件中的方法。The following example overrides the RenderChildren method in a custom server control. 它确定当前控件在其ControlCollection对象中是否有任何子控件。It determines whether the current control has any child controls in its ControlCollection object. 如果它存在,则使用Count属性来循环访问集合。If it does, it uses the Count property to iterate through the collection. 在遇到每个子控件时,它使用RenderControl方法将子控件及其所有子控件呈现给包含页。As it encounters each child control, it uses the RenderControl method to render the child control, and all of its child controls, to the containing page. 传递给此方法的Render 对象由方法实例化。XhtmlTextWriterThe XhtmlTextWriter object that is passed to this method is instantiated by the Render method.

// Override default implementation to Render children according to needs. 
protected override void RenderChildren(HtmlTextWriter output)
{
   if (HasControls())
   {
      // Render Children in reverse order.
      for(int i = Controls.Count - 1; i >= 0; --i)
      {
         Controls[i].RenderControl(output);
      }
   }         
}

protected override void Render(HtmlTextWriter output)
{       
   output.Write("<br>Message from Control : " + Message);       
   output.Write("Showing Custom controls created in reverse" +
                                                    "order");         
   // Render Controls.
   RenderChildren(output);
}
' Override default implementation to Render children according to needs. 
      Protected Overrides Sub RenderChildren(output As HtmlTextWriter)
         If HasControls() Then
            ' Render Children in reverse order.
            Dim i As Integer

            For i = Controls.Count - 1 To 0 Step -1
               Controls(i).RenderControl(output)
            Next

         End If
      End Sub
      
      
      Protected Overrides Sub Render(output As HtmlTextWriter)
         output.Write(("<br>Message from Control : " + Message))
         output.Write(("Showing Custom controls created in reverse" + "order"))
         ' Render Controls.
         RenderChildren(output)
      End Sub
   End Class

注解

如果服务器控件的Visible属性设置为true,则此方法将确定是否为该页启用跟踪。If a server control's Visible property is set to true, this method determines whether tracing is enabled for the page. 如果是这样,它将存储与控件相关联的跟踪信息,并将服务器控件内容呈现到页面。If so, it stores trace information associated with the control, and renders the server control content to the page.

此方法在呈现期间由页面自动调用,但可由自定义控件开发人员重写。This method is automatically called by the page during the rendering, but can be overridden by custom control developers.

另请参阅

RenderControl(HtmlTextWriter, ControlAdapter) RenderControl(HtmlTextWriter, ControlAdapter) RenderControl(HtmlTextWriter, ControlAdapter) RenderControl(HtmlTextWriter, ControlAdapter)

使用提供的 HtmlTextWriter 对象将服务器控件内容输出到提供的 ControlAdapter 对象。Outputs server control content to a provided HtmlTextWriter object using a provided ControlAdapter object.

protected:
 void RenderControl(System::Web::UI::HtmlTextWriter ^ writer, System::Web::UI::Adapters::ControlAdapter ^ adapter);
protected void RenderControl (System.Web.UI.HtmlTextWriter writer, System.Web.UI.Adapters.ControlAdapter adapter);
member this.RenderControl : System.Web.UI.HtmlTextWriter * System.Web.UI.Adapters.ControlAdapter -> unit
Protected Sub RenderControl (writer As HtmlTextWriter, adapter As ControlAdapter)

参数

writer
HtmlTextWriter HtmlTextWriter HtmlTextWriter HtmlTextWriter

接收控件内容的 HtmlTextWriterThe HtmlTextWriter that receives the control content.

adapter
ControlAdapter ControlAdapter ControlAdapter ControlAdapter

定义呈现的 ControlAdapterThe ControlAdapter that defines the rendering.

注解

可以从 Web 请求信息的各种设备和浏览器中使用 ASP.NET 网页。ASP.NET Web pages are usable across a wide range of devices and browsers that can request information from the Web. 属性返回在请求设备或浏览器的屏幕上呈现控件的对象。ControlAdapter AdapterThe Adapter property returns the ControlAdapter object that renders the control on the requesting device or browser's screen.

有关适配器的详细信息,请参阅自适应控制行为的体系结构概述For more information about adapters, see Architectural Overview of Adaptive Control Behavior.

如果服务器控件的Visible属性设置为true并为该页启用了跟踪,则将捕获与该控件关联的跟踪信息。If a server control's Visible property is set to true and tracing is enabled for the page, then trace information associated with the control is captured.

继承者说明

重写自RenderControl(HtmlTextWriter, ControlAdapter)定义控件中的方法时,调用基类方法以确保正确捕获跟踪信息。When overriding the RenderControl(HtmlTextWriter, ControlAdapter) method in custom controls, call the base class method to ensure trace information is correctly captured.

另请参阅

适用于