Szerkesztés

Megosztás a következőn keresztül:


WebPartChrome.RenderPartContents(HtmlTextWriter, WebPart) Method

Definition

Renders the main content area of a WebPart control, excluding the header and footer.

protected:
 virtual void RenderPartContents(System::Web::UI::HtmlTextWriter ^ writer, System::Web::UI::WebControls::WebParts::WebPart ^ webPart);
protected virtual void RenderPartContents (System.Web.UI.HtmlTextWriter writer, System.Web.UI.WebControls.WebParts.WebPart webPart);
abstract member RenderPartContents : System.Web.UI.HtmlTextWriter * System.Web.UI.WebControls.WebParts.WebPart -> unit
override this.RenderPartContents : System.Web.UI.HtmlTextWriter * System.Web.UI.WebControls.WebParts.WebPart -> unit
Protected Overridable Sub RenderPartContents (writer As HtmlTextWriter, webPart As WebPart)

Parameters

writer
HtmlTextWriter

The HtmlTextWriter that receives the webPart content.

webPart
WebPart

The control currently being rendered.

Examples

The following code example demonstrates use of the RenderPartContents method. For the full code required to run the example, see the Example section of the WebPartChrome class overview topic.

The following section from the code example demonstrates how to override the RenderPartContents method. The overridden method does two things to customize the rendering for the body of the WebPart control. First, it checks to determine whether the control is currently selected, and if so, writes out a string and does not render the contents. Second, if the control is not selected, and if the control's zone is of type MyZone, the method renders the control. This latter check could be used if you wanted to ensure that a custom WebPartChrome class can be used only to render WebPart controls in a specific type of WebPartZone zone that is designed to contain the WebPartChrome object.

protected override void RenderPartContents(HtmlTextWriter writer, 
  WebPart part)
{

    if (part == this.WebPartManager.SelectedWebPart)
      HttpContext.Current.Response.Write("<span>Not rendered</span>");
    else
      if(this.Zone.GetType() == typeof(MyZone))
        part.RenderControl(writer);
}
Protected Overrides Sub RenderPartContents _
  (ByVal writer As HtmlTextWriter, ByVal part As WebPart)

  If part Is Me.WebPartManager.SelectedWebPart Then
    HttpContext.Current.Response.Write("<span>Not rendered</span>")
  Else
    If (Me.Zone.GetType() Is GetType(MyZone)) Then
      part.RenderControl(writer)
    End If
  End If

End Sub

If you load the Web page in a browser, you can see that the content of each control is rendered normally. If you switch the page into design mode (by selecting Design in the Display Mode drop-down list control) and drag one of the controls into the empty zone labeled WebPartZone2, the contents of the control are rendered differently, because the custom WebPartChrome object is not being used for the rendering in a standard zone. This is the same effect that you would achieve if you tried to use the custom WebPartChrome class with any other zone besides the MyZone class, due to the preceding source code.

Remarks

The RenderPartContents method enables you to override the rendering of the body area of webPart, while leaving rendering of the header and footer to the default rendering.

Notes to Inheritors

You can optionally override the RenderPartContents(HtmlTextWriter, WebPart) method. If so, you can simply perform whatever rendering customizations you want for webPart, and then call its RenderControl(HtmlTextWriter) method. If you also want to rely on the default rendering in the event of connection errors, call the base method first, and then customize the writer that is returned from the base method.

Applies to

See also