แก้ไข

แชร์ผ่าน


WebPartChrome.WebPartManager Property

Definition

Gets a reference to the current WebPartManager instance.

protected:
 property System::Web::UI::WebControls::WebParts::WebPartManager ^ WebPartManager { System::Web::UI::WebControls::WebParts::WebPartManager ^ get(); };
protected System.Web.UI.WebControls.WebParts.WebPartManager WebPartManager { get; }
member this.WebPartManager : System.Web.UI.WebControls.WebParts.WebPartManager
Protected ReadOnly Property WebPartManager As WebPartManager

Property Value

A reference to the current WebPartManager on the Web page.

Examples

This code example demonstrates use of the WebPartManager property. For the full code required to run the example, see the Example section of the WebPartChrome class overview topic.

The following code example uses the WebPartManager property to determine whether the current WebPart control being rendered is the selected control, which in this example means that the page is in edit view, and the control is currently being edited. If these conditions are true, the body of the control is not rendered, and a string is written in its place.

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 switch the page into edit mode by selecting Edit in the Display Mode drop-down list control. You can click the edit verb in the verbs menu of either of the controls; when the page is rendered, the body of the control selected for editing is not rendered. However, if you drag the control into the empty zone labeled WebPartZone2, the body of the control is rendered. This is because the second zone is a standard WebPartZone zone, and it does not use the custom WebPartChrome class in this example to render the WebPart controls.

Remarks

The WebPartManager property provides a reference to the current WebPartManager instance on the page.

Applies to

See also