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. XhtmlTextWriter傳遞至這個方法的物件具現化Render方法。The 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 'RenderChildren
      
      
      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.

備註

ASP.NET Web pages 可跨各種不同的裝置和瀏覽器可從 Web 要求的資訊。ASP.NET Web pages are usable across a wide range of devices and browsers that can request information from the Web. Adapter屬性會傳回ControlAdapter提出要求的裝置或瀏覽器的螢幕呈現控制項的物件。The 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.

另請參閱

適用於