Control.RenderControl 方法

定義

輸出伺服器控制項內容,並在啟用追蹤功能的情況下,儲存有關控制項的追蹤資訊。Outputs server control content and stores tracing information about the control if tracing is enabled.

多載

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)

使用提供的 HtmlTextWriter 物件,輸出伺服器控制項內容至提供的 ControlAdapter 物件。Outputs server control content to a provided HtmlTextWriter object using a provided ControlAdapter object.

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 物件。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
      
      
      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)

使用提供的 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

接收控制項內容的 HtmlTextWriterThe HtmlTextWriter that receives the control content.

adapter
ControlAdapter

定義呈現的 ControlAdapterThe ControlAdapter that defines the rendering.

備註

ASP.NET 網頁可在各種不同的裝置和瀏覽器中使用,以便從 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.

另請參閱

適用於