WebPartManager 类

定义

用作 Web 部件控件集的中心类,管理所有 Web 部件控件、功能和网页上发生的事件。

public ref class WebPartManager : System::Web::UI::Control, System::Web::UI::INamingContainer, System::Web::UI::WebControls::WebParts::IPersonalizable
[System.ComponentModel.Bindable(false)]
public class WebPartManager : System.Web.UI.Control, System.Web.UI.INamingContainer, System.Web.UI.WebControls.WebParts.IPersonalizable
[<System.ComponentModel.Bindable(false)>]
type WebPartManager = class
    inherit Control
    interface INamingContainer
    interface IPersonalizable
Public Class WebPartManager
Inherits Control
Implements INamingContainer, IPersonalizable
继承
WebPartManager
属性
实现

示例

下面的代码示例演示了 控件的 WebPartManager 声明和编程使用。

该代码示例包含四个部分:

  • 一个用户控件,可用于更改 Web 部件页上的显示模式。

  • 包含两个可以连接的自定义 WebPart 控件和一个 <asp:webpartmanager> 元素的网页。

  • 一个源代码文件,其中包含两个自定义 WebPart 控件和一个自定义接口。

  • 说明该示例在浏览器中的工作原理。

鉴于页面上存在的 Web 部件控件,用户控件具有一个下拉列表控件,该控件显示页面上可能的显示模式。 在此代码示例的网页中,此用户控件声明在页面标记中的 元素的正下方 WebPartManager ,并且网页顶部附近有一个 Register 指令来注册控件。 有关显示模式的详细信息和此控件中的源代码说明,请参阅 演练:更改 Web 部件页上的显示模式

<%@ control language="C#" classname="DisplayModeMenuCS"%>
<script runat="server">
  
 // Use a field to reference the current WebPartManager.
  WebPartManager _manager;

  void Page_Init(object sender, EventArgs e)
  {
    Page.InitComplete += new EventHandler(InitComplete);
  }  

  void InitComplete(object sender, System.EventArgs e)
  {
    _manager = WebPartManager.GetCurrentWebPartManager(Page);

    String browseModeName = WebPartManager.BrowseDisplayMode.Name;

    // Fill the dropdown with the names of supported display modes.
    foreach (WebPartDisplayMode mode in _manager.SupportedDisplayModes)
    {
      String modeName = mode.Name;
      // Make sure a mode is enabled before adding it.
      if (mode.IsEnabled(_manager))
      {
        ListItem item = new ListItem(modeName, modeName);
        DisplayModeDropdown.Items.Add(item);
      }
    }

    // If shared scope is allowed for this user, display the scope-switching
    // UI and select the appropriate radio button for the current user scope.
    if (_manager.Personalization.CanEnterSharedScope)
    {
      Panel2.Visible = true;
      if (_manager.Personalization.Scope == PersonalizationScope.User)
        RadioButton1.Checked = true;
      else
        RadioButton2.Checked = true;
    }
    
  }
 
  // Change the page to the selected display mode.
  void DisplayModeDropdown_SelectedIndexChanged(object sender, EventArgs e)
  {
    String selectedMode = DisplayModeDropdown.SelectedValue;

    WebPartDisplayMode mode = _manager.SupportedDisplayModes[selectedMode];
    if (mode != null)
      _manager.DisplayMode = mode;
  }

  // Set the selected item equal to the current display mode.
  void Page_PreRender(object sender, EventArgs e)
  {
    ListItemCollection items = DisplayModeDropdown.Items;
    int selectedIndex = 
      items.IndexOf(items.FindByText(_manager.DisplayMode.Name));
    DisplayModeDropdown.SelectedIndex = selectedIndex;
  }

  // Reset all of a user's personalization data for the page.
  protected void LinkButton1_Click(object sender, EventArgs e)
  {
    _manager.Personalization.ResetPersonalizationState();
  }

  // If not in User personalization scope, toggle into it.
  protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
  {
    if (_manager.Personalization.Scope == PersonalizationScope.Shared)
      _manager.Personalization.ToggleScope();
  }

  // If not in Shared scope, and if user is allowed, toggle the scope.
  protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
  {
    if (_manager.Personalization.CanEnterSharedScope && 
        _manager.Personalization.Scope == PersonalizationScope.User)
      _manager.Personalization.ToggleScope();
  }
</script>
<div>
  <asp:Panel ID="Panel1" runat="server" 
    Borderwidth="1" 
    Width="230" 
    BackColor="lightgray"
    Font-Names="Verdana, Arial, Sans Serif" >
    <asp:Label ID="Label1" runat="server" 
      Text=" Display Mode" 
      Font-Bold="true"
      Font-Size="8"
      Width="120" 
      AssociatedControlID="DisplayModeDropdown"/>
    <asp:DropDownList ID="DisplayModeDropdown" runat="server"  
      AutoPostBack="true" 
      Width="120"
      OnSelectedIndexChanged="DisplayModeDropdown_SelectedIndexChanged" />
    <asp:LinkButton ID="LinkButton1" runat="server"
      Text="Reset User State" 
      ToolTip="Reset the current user's personalization data for the page."
      Font-Size="8" 
      OnClick="LinkButton1_Click" />
    <asp:Panel ID="Panel2" runat="server" 
      GroupingText="Personalization Scope"
      Font-Bold="true"
      Font-Size="8" 
      Visible="false" >
      <asp:RadioButton ID="RadioButton1" runat="server" 
        Text="User" 
        AutoPostBack="true"
        GroupName="Scope" OnCheckedChanged="RadioButton1_CheckedChanged" />
      <asp:RadioButton ID="RadioButton2" runat="server" 
        Text="Shared" 
        AutoPostBack="true"
        GroupName="Scope" 
        OnCheckedChanged="RadioButton2_CheckedChanged" />
    </asp:Panel>
  </asp:Panel>
</div>
<%@ control language="vb" classname="DisplayModeMenuVB"%>
<script runat="server">
  ' Use a field to reference the current WebPartManager.
  Dim _manager As WebPartManager

  Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
    AddHandler Page.InitComplete, AddressOf InitComplete
  End Sub

  Sub InitComplete(ByVal sender As Object, ByVal e As System.EventArgs)
    _manager = WebPartManager.GetCurrentWebPartManager(Page)
      
    Dim browseModeName As String = WebPartManager.BrowseDisplayMode.Name
      
    ' Fill the dropdown with the names of supported display modes.
    Dim mode As WebPartDisplayMode
    For Each mode In _manager.SupportedDisplayModes
      Dim modeName As String = mode.Name
      ' Make sure a mode is enabled before adding it.
      If mode.IsEnabled(_manager) Then
        Dim item As New ListItem(modeName, modeName)
        DisplayModeDropdown.Items.Add(item)
      End If
    Next mode
      
    ' If shared scope is allowed for this user, display the scope-switching
    ' UI and select the appropriate radio button for the current user scope.
    If _manager.Personalization.CanEnterSharedScope Then
      Panel2.Visible = True
      If _manager.Personalization.Scope = PersonalizationScope.User Then
        RadioButton1.Checked = True
      Else
        RadioButton2.Checked = True
      End If
    End If
   
  End Sub

  ' Change the page to the selected display mode.
  Sub DisplayModeDropdown_SelectedIndexChanged(ByVal sender As Object, _
    ByVal e As EventArgs)
    
    Dim selectedMode As String = DisplayModeDropdown.SelectedValue   
    Dim mode As WebPartDisplayMode = _
      _manager.SupportedDisplayModes(selectedMode)
    If Not (mode Is Nothing) Then
      _manager.DisplayMode = mode
    End If

  End Sub
   
  ' Set the selected item equal to the current display mode.
  Sub Page_PreRender(ByVal sender As Object, ByVal e As EventArgs)
    Dim items As ListItemCollection = DisplayModeDropdown.Items
    Dim selectedIndex As Integer = _
      items.IndexOf(items.FindByText(_manager.DisplayMode.Name))
    DisplayModeDropdown.SelectedIndex = selectedIndex

  End Sub

  ' Reset all of a user's personalization data for the page.
  Protected Sub LinkButton1_Click(ByVal sender As Object, _
    ByVal e As EventArgs)
    
    _manager.Personalization.ResetPersonalizationState()
    
  End Sub

  ' If not in User personalization scope, toggle into it.
  Protected Sub RadioButton1_CheckedChanged(ByVal sender As Object, _
    ByVal e As EventArgs)
    
    If _manager.Personalization.Scope = PersonalizationScope.Shared Then
      _manager.Personalization.ToggleScope()
    End If

  End Sub
   
  ' If not in Shared scope, and if user is allowed, toggle the scope.
  Protected Sub RadioButton2_CheckedChanged(ByVal sender As Object, _
    ByVal e As EventArgs)
    
    If _manager.Personalization.CanEnterSharedScope AndAlso _
      _manager.Personalization.Scope = PersonalizationScope.User Then
      _manager.Personalization.ToggleScope()
    End If

  End Sub

</script>
<div>
  <asp:Panel ID="Panel1" runat="server" 
    Borderwidth="1" 
    Width="230" 
    BackColor="lightgray"
    Font-Names="Verdana, Arial, Sans Serif" >
    <asp:Label ID="Label1" runat="server" 
      Text=" Display Mode" 
      Font-Bold="true"
      Font-Size="8"
      Width="120" 
      AssociatedControlID="DisplayModeDropdown"/>
    <asp:DropDownList ID="DisplayModeDropdown" runat="server"  
      AutoPostBack="true" 
      Width="120"
      OnSelectedIndexChanged="DisplayModeDropdown_SelectedIndexChanged" />
    <asp:LinkButton ID="LinkButton1" runat="server"
      Text="Reset User State" 
      ToolTip="Reset the current user's personalization data for the page."
      Font-Size="8" 
      OnClick="LinkButton1_Click" />
    <asp:Panel ID="Panel2" runat="server" 
      GroupingText="Personalization Scope"
      Font-Bold="true"
      Font-Size="8" 
      Visible="false" >
      <asp:RadioButton ID="RadioButton1" runat="server" 
        Text="User" 
        AutoPostBack="true"
        GroupName="Scope" OnCheckedChanged="RadioButton1_CheckedChanged" />
      <asp:RadioButton ID="RadioButton2" runat="server" 
        Text="Shared" 
        AutoPostBack="true"
        GroupName="Scope" 
        OnCheckedChanged="RadioButton2_CheckedChanged" />
    </asp:Panel>
  </asp:Panel>
</div>

网页的声明性标记包含 Register 用户控件和自定义控件的指令。 有一个 <asp:webpartmanager> 元素、一个 <asp:webpartzone> 用于包含自定义控件的元素和一个 <asp:connectionszone> 元素。 该页还包含一些内联代码,用于处理控件的连接相关事件 WebPartManager ;在连接和断开连接控件时,可以看到此代码的效果。

<%@ Page Language="C#" %>
<%@ register TagPrefix="uc1" 
  TagName="DisplayModeMenuCS" 
  Src="DisplayModeMenuCS.ascx" %>
<%@ register tagprefix="aspSample" 
  Namespace="Samples.AspNet.CS.Controls" 
  Assembly="ConnectionSampleCS" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
 
  private void UpdateLabelData(int wpCount, int connCount)
  {
    Label1.Text = "WebPart Control Count:  " + wpCount.ToString();
    Label2.Text = "Connections Count: " + connCount.ToString();
  }

  protected void WebPartManager1_WebPartsConnected(object sender, WebPartConnectionsEventArgs e)
  {
    UpdateLabelData(WebPartManager1.WebParts.Count,
      WebPartManager1.Connections.Count);
  }

  protected void WebPartManager1_WebPartsDisconnected(object sender, WebPartConnectionsEventArgs e)
  {
    UpdateLabelData(WebPartManager1.WebParts.Count,
      WebPartManager1.Connections.Count);
  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
      <!-- Reference the WebPartManager control. -->
      <asp:WebPartManager ID="WebPartManager1" runat="server"  
        OnWebPartsConnected="WebPartManager1_WebPartsConnected" 
        OnWebPartsDisconnected="WebPartManager1_WebPartsDisconnected" />
    <div>
      <uc1:DisplayModeMenuCS ID="displaymode1" runat="server" />
      <!-- Reference consumer and provider controls in a zone. -->
      <asp:WebPartZone ID="WebPartZone1" runat="server">
        <ZoneTemplate>
          <aspSample:ZipCodeWebPart ID="zip1" 
            runat="server" 
            Title="Zip Code Control"/>
          <aspSample:WeatherWebPart ID="weather1" 
            runat="server" 
            Title="Weather Control" />
        </ZoneTemplate>
      </asp:WebPartZone>
      <hr />
      <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
      <br />
      <asp:Label ID="Label2" runat="server" Text=""></asp:Label>
      <!-- Add a ConnectionsZone so users can connect controls. -->
      <asp:ConnectionsZone ID="ConnectionsZone1" runat="server" />
    </div>
    </form>
</body>
</html>
<%@ Page Language="vb" %>
<%@ register TagPrefix="uc1" 
  TagName="DisplayModeMenuVB" 
  Src="DisplayModeMenuVB.ascx" %>
<%@ register tagprefix="aspSample" 
  Namespace="Samples.AspNet.VB.Controls" 
  Assembly="ConnectionSampleVB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Protected Sub WebPartManager1_WebPartsConnected( _
    ByVal sender As Object, _
    ByVal e As System.Web.UI.WebControls.WebParts.WebPartConnectionsEventArgs)
    
    UpdateLabelData(WebPartManager1.WebParts.Count, _
      WebPartManager1.Connections.Count)
    
  End Sub

  Protected Sub WebPartManager1_WebPartsDisconnected( _
    ByVal sender As Object, _
    ByVal e As System.Web.UI.WebControls.WebParts.WebPartConnectionsEventArgs)
    
    UpdateLabelData(WebPartManager1.WebParts.Count, _
      WebPartManager1.Connections.Count)
    
  End Sub
  
  Private Sub UpdateLabelData(ByVal wpCount As Integer, _
    ByVal connCount As Integer)
    
    Label1.Text = "WebPart Control Count:  " & wpCount.ToString()
    Label2.Text = "Connections Count: " & connCount.ToString()
    
  End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
      <!-- Reference the WebPartManager control. -->
      <asp:WebPartManager ID="WebPartManager1" runat="server" OnWebPartsConnected="WebPartManager1_WebPartsConnected" OnWebPartsDisconnected="WebPartManager1_WebPartsDisconnected" />
    <div>
      <uc1:DisplayModeMenuVB ID="displaymode1" runat="server" />
      <!-- Reference consumer and provider controls in a zone. -->
      <asp:WebPartZone ID="WebPartZone1" runat="server">
        <ZoneTemplate>
          <aspSample:ZipCodeWebPart ID="zip1" 
            runat="server" 
            Title="Zip Code Control"/>
          <aspSample:WeatherWebPart ID="weather1" 
            runat="server" 
            Title="Weather Control" />
        </ZoneTemplate>
      </asp:WebPartZone>
      <hr />
      <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
      <br />
      <asp:Label ID="Label2" runat="server" Text=""></asp:Label>
      <!-- Add a ConnectionsZone so users can connect controls. -->
      <asp:ConnectionsZone ID="ConnectionsZone1" runat="server" />
    </div>
    </form>
</body>
</html>

该示例的第三部分是控件的源代码。 请注意,有一个名为 的 IZipCode接口,此接口在 类中 ZipCodeWebPart 实现。 此类具有一个名为 ProvideIZipCode 的特殊回调方法,该方法用作提供程序。 另一种名为 WeatherWebPart的类型也通过名为 GetIZipCode的特殊方法实现,该方法使控件能够充当另一个控件的使用者。

若要运行代码示例,必须编译此源代码。 可以显式编译它,并将生成的程序集放入网站的 Bin 文件夹或全局程序集缓存中。 或者,可以将源代码放入站点的“App_Code”文件夹中,并在运行时动态编译源代码。 此代码示例假定已将源编译为程序集,并且 Register 网页中的 指令引用程序集名称。 有关演示如何编译的演练,请参阅 演练:开发和使用自定义 Web 服务器控件

namespace Samples.AspNet.CS.Controls
{
  using System;
  using System.Web;
  using System.Web.Security;
  using System.Security.Permissions;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Web.UI.WebControls.WebParts;

  [AspNetHostingPermission(SecurityAction.Demand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  [AspNetHostingPermission(SecurityAction.InheritanceDemand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  public interface IZipCode
  {
    string ZipCode { get; set;}
  }

  [AspNetHostingPermission(SecurityAction.Demand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  [AspNetHostingPermission(SecurityAction.InheritanceDemand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  public class ZipCodeWebPart : WebPart, IZipCode
  {
    string zipCodeText = String.Empty;
    TextBox input;
    Button send;

    public ZipCodeWebPart()
    {
    }

    // Make the implemented property personalizable to save 
    // the Zip Code between browser sessions.
    [Personalizable()]
    public virtual string ZipCode
    {
      get { return zipCodeText; }
      set { zipCodeText = value; }
    }

    // This is the callback method that returns the provider.
    [ConnectionProvider("Zip Code")]
    public IZipCode ProvideIZipCode()
    {
      return this;
    }

    protected override void CreateChildControls()
    {
      Controls.Clear();
      input = new TextBox();
      this.Controls.Add(input);
      send = new Button();
      send.Text = "Enter 5-digit Zip Code";
      send.Click += new EventHandler(this.submit_Click);
      this.Controls.Add(send);
    }

    private void submit_Click(object sender, EventArgs e)
    {
      if (!string.IsNullOrEmpty(input.Text))
      {
        zipCodeText = Page.Server.HtmlEncode(input.Text);
        input.Text = String.Empty;
      }
    }
  }

  [AspNetHostingPermission(SecurityAction.Demand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  [AspNetHostingPermission(SecurityAction.InheritanceDemand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  public class WeatherWebPart : WebPart
  {
    private IZipCode _provider;
    string _zipSearch;
    Label DisplayContent;

    // This method is identified by the ConnectionConsumer 
    // attribute, and is the mechanism for connecting with 
    // the provider. 
    [ConnectionConsumer("Zip Code")]
    public void GetIZipCode(IZipCode Provider)
    {
      _provider = Provider;
    }
    
    protected override void OnPreRender(EventArgs e)
    {
      EnsureChildControls();

      if (this._provider != null)
      {
        _zipSearch = _provider.ZipCode.Trim();
        DisplayContent.Text = "My Zip Code is:  " + _zipSearch;
      }
    }

    protected override void CreateChildControls()
    {
      Controls.Clear();
      DisplayContent = new Label();
      this.Controls.Add(DisplayContent);
    }
  }
}
Imports System.Web
Imports System.Web.Security
Imports System.Security.Permissions
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts

Namespace Samples.AspNet.VB.Controls

  <AspNetHostingPermission(SecurityAction.Demand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
  <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
  Public Interface IZipCode

    Property ZipCode() As String

  End Interface

  <AspNetHostingPermission(SecurityAction.Demand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
  <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
  Public Class ZipCodeWebPart
    Inherits WebPart
    Implements IZipCode
    Private zipCodeText As String = String.Empty
    Private input As TextBox
    Private send As Button

    Public Sub New()
    End Sub

    ' Make the implemented property personalizable to save 
    ' the Zip Code between browser sessions.
    <Personalizable()> _
    Public Property ZipCode() As String _
      Implements IZipCode.ZipCode

      Get
        Return zipCodeText
      End Get
      Set(ByVal value As String)
        zipCodeText = value
      End Set
    End Property

    ' This is the callback method that returns the provider.
    <ConnectionProvider("Zip Code")> _
    Public Function ProvideIZipCode() As IZipCode
      Return Me
    End Function


    Protected Overrides Sub CreateChildControls()
      Controls.Clear()
      input = New TextBox()
      Me.Controls.Add(input)
      send = New Button()
      send.Text = "Enter 5-digit Zip Code"
      AddHandler send.Click, AddressOf Me.submit_Click
      Me.Controls.Add(send)

    End Sub


    Private Sub submit_Click(ByVal sender As Object, _
      ByVal e As EventArgs)

      If input.Text <> String.Empty Then
        zipCodeText = Page.Server.HtmlEncode(input.Text)
        input.Text = String.Empty
      End If

    End Sub

  End Class

  <AspNetHostingPermission(SecurityAction.Demand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
  <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
  Public Class WeatherWebPart
    Inherits WebPart
    Private _provider As IZipCode
    Private _zipSearch As String
    Private DisplayContent As Label

    ' This method is identified by the ConnectionConsumer 
    ' attribute, and is the mechanism for connecting with 
    ' the provider. 
    <ConnectionConsumer("Zip Code")> _
    Public Sub GetIZipCode(ByVal Provider As IZipCode)
      _provider = Provider
    End Sub


    Protected Overrides Sub OnPreRender(ByVal e As EventArgs)
      EnsureChildControls()

      If Not (Me._provider Is Nothing) Then
        _zipSearch = _provider.ZipCode.Trim()
    DisplayContent.Text = "My Zip Code is:  " + _zipSearch
      End If

    End Sub

    Protected Overrides Sub CreateChildControls()
      Controls.Clear()
      DisplayContent = New Label()
      Me.Controls.Add(DisplayContent)

    End Sub

  End Class

End Namespace

在浏览器中加载网页后,单击“ 显示模式 ”下拉列表控件,然后选择“ 连接 ”将页面切换到连接模式。 连接模式使用 <asp:connectionszone> 元素在控件之间创建连接。 在连接模式下,单击 “邮政编码” 控件标题栏中的向下箭头以激活其谓词菜单,然后单击“ 连接”。 连接 UI 出现后,单击“ 创建与使用者的连接 ”链接。 此时将显示一个包含下拉列表控件的单元格。 在下拉列表中选择“ 天气控制 ”,然后单击“ 连接 ”以完成两个控件的连接。 单击“ 关闭”,然后使用 “显示模式 ”下拉列表将页面返回到正常浏览模式。 可以输入邮政编码,使用者控件将使用输入的值进行更新。 由于 属性 ZipCode 在源代码中用 属性标记 Personalizable ,因此该属性值将在浏览器会话中保留,从而保存用户输入的值。 更复杂的使用者控件可以获取邮政编码信息,根据代码查找天气信息,并将其显示给用户。

注解

控件 WebPartManager 充当 Web 部件应用程序的中心或控制中心。 使用 Web 部件控件的每个页面上必须有一个控件实例,而且只有一个WebPartManager 控件实例。 与 Web 部件应用程序的大多数方面一样,控件 WebPartManager 仅适用于经过身份验证的用户。 此外,其功能几乎完全适用于驻留在从 WebZone 类继承的 Web 部件区域中的服务器控件。 驻留在这些区域外部的页面上的服务器控件可能具有极少的 Web 部件功能或与控件的 WebPartManager 交互。

作为页面上 Web 部件功能的中心,控件 WebPartManager 执行下表中所述的任务类型。

任务类别 控件的作用
跟踪 Web 部件控件 跟踪提供 Web 部件功能的页面上许多不同类型的控件,包括 WebPart 控件、连接、区域等。
添加和删除 Web 部件控件 提供用于在页面上添加、删除和关闭 WebPart 控件的方法。
管理连接 在控件之间创建连接,并监视连接以及添加和删除它们的过程。
个性化设置控件和页面 使用户能够将控件移动到页面上的不同位置,并启动用户可以在其中编辑控件的外观、属性和行为的视图。 在每个页面上维护特定于用户的个性化设置。
在不同页面视图之间切换 在页面的不同专用视图之间切换页面,以便用户可以执行某些任务,例如更改页面布局或编辑控件。
引发 Web 部件生命周期事件 定义、引发并使开发人员能够处理 Web 部件控件的生命周期事件,例如添加、移动、连接或删除控件时。
启用控件的导入和导出 导出包含控件属性状态的 WebPart XML 流,并允许用户导入文件,以便于在其他页面或网站中个性化复杂控件。

WebPartManager 具有大量属性。 与 WebPartManager 跟踪其他控件的角色一致,它具有许多引用 Web 部件控件或其他特殊 Web 部件对象的集合的属性。 AvailableTransformersConnectionsControlsDisplayModesDynamicConnectionsSupportedDisplayModesWebPartsZones 属性是控件用于WebPartManager跟踪和其他管理任务的所有集合。

另一组属性包含可自定义的警告,这些警告适用于 Web 部件应用程序中发生的某些情况。 CloseProviderWarning其中包括 、 DeleteWarningExportSensitiveDataWarning 属性。

WebPartManager 重写其一些基本继承的属性,这些属性由许多 Web 服务器控件使用。 其中包括 EnableThemingSkinIDVisible 属性。

最后,有一组属性可用于访问应用程序的当前状态。 属性 DisplayMode 指示页面处于的当前显示模式。 属性 EnableClientScript 指示是否允许控件呈现客户端脚本,这与用户可能具有具有不同功能的浏览器或关闭脚本的情况相关。 属性 Internals 可用于引用实用工具类,该类包含对许多用于扩展性案例的重要 Web 部件方法的调用。 通过在类) 的单独类 (WebPartManagerInternals 隐藏对这些方法的调用, WebPartManager 可以简化类自己的 API。 属性 Personalization 提供对个性化设置的访问,这些对象存储用户的个性化设置并将该数据保存到永久存储中。 属性 SelectedWebPart 指示用户或应用程序当前选择了页面上的哪个 WebPart 控件。 属性 IPersonalizable.IsDirty 指示控件上的 WebPart 自定义个性化设置数据是否已更改。

控件 WebPartManager 包含五种内置显示模式或网页视图。 开发人员可以通过扩展 类或 ToolZone 类等WebZone类型来创建自定义显示模式来扩展此功能。 用户可以将页面切换到各种显示模式,前提是页面上存在与给定显示模式对应的适当类型的控件。

注意

可以扩展此功能,以便用户可以切换到自定义显示模式,而无需在页面上具有相应的区域。 但是,默认行为是显示模式对应于区域。

标准显示模式由 类中的 WebPartManager 公共字段表示。 下表汇总了字段及其引用的显示模式。 如上所述,页面的当前显示模式始终在 属性中 DisplayMode 引用,并且给定页面上存在的区域类型,在特定页面上可能的显示模式集包含在 属性中 SupportedDisplayModes

字段 显示模式详细信息
BrowseDisplayMode 网页的普通用户视图;默认和最常见的显示模式。
DesignDisplayMode 用户可以在其中重新排列或删除控件以更改页面布局的视图。
EditDisplayMode 编辑用户界面 (UI) 变为可见的视图;用户可以编辑在正常浏览模式下可见的控件的外观、属性和行为。
CatalogDisplayMode 目录 UI 变为可见的视图;用户可以从可用控件的目录将控件添加到页面。
ConnectDisplayMode 连接 UI 变为可见的视图;用户可以连接、管理或断开控件之间的连接。

控件 WebPartManager 还包含许多在 Web 部件页和控件的生命周期中至关重要的事件。 这些事件提供对 Web 部件控件行为的精确编程控制。 大多数方法直接与 WebPart 放置在区域中 WebPartZoneBase 的控件 (或其他服务器或用户控件相关,以便它们可以像控件) 一样 WebPart 运行。 但是,一些事件与页面上的或连接的状态有关。 下表列出了可用事件并汇总了其用途。

注意

在下表中的所有情况下,“control”一词是指 WebPart 驻留在区域中并在运行时随 GenericWebPart 对象包装的控件或任何服务器控件。

事件 说明
AuthorizeWebPart 在将控件添加到页面之前发生,以验证该控件是否已获得授权。
ConnectionsActivated 在激活页面上的所有连接后发生。
ConnectionsActivating 在激活页面上的所有连接之前发生。
DisplayModeChanged 在页面的当前显示模式更改后发生。
DisplayModeChanging 发生在更改页面显示模式的过程之前。
SelectedWebPartChanged 在取消选择控件后发生。
SelectedWebPartChanging 在取消选择控件的过程之前发生。
WebPartAdded 在控件添加到区域后发生。
WebPartAdding 在将控件添加到区域的过程之前发生。
WebPartClosed 在控件关闭 (从页面) 中删除后发生。
WebPartClosing 在关闭控件的过程之前发生。
WebPartDeleted 在动态控件的实例 (以编程方式创建或从目录) 添加的实例已被永久删除后发生。
WebPartDeleting 发生在删除动态控件的过程之前。
WebPartMoved 在控件在其区域内移动或移动到另一个区域之后发生。
WebPartMoving 在移动控件的过程之前发生。
WebPartsConnected 在选择用于参与连接的两个控件已建立连接之后发生。
WebPartsConnecting 在连接两个控件的过程之前发生。
WebPartsDisconnected 在两个连接的控件断开连接后发生。
WebPartsDisconnecting 在断开连接两个控件的过程之前发生。

控件 WebPartManager 具有许多用于管理 Web 部件页的方法。 一大组方法(此处未列出)是名称采用 OnEventName 格式的方法。 这些方法通常会引发其关联的事件,并为 事件提供类型 WebPartEventHandler为 的处理程序。 从 类继承 WebPartManager 的开发人员可以重写其中大多数方法。 此外,页面开发人员可以为与这些方法关联的事件提供自定义处理程序。 例如,对于 WebPartAdded 事件,页面开发人员可以将属性 OnWebPartAdded 添加到 <asp:webpartmanager> 网页标记中的 元素,然后将自定义方法名称分配给 属性,以便为事件提供自定义处理。 属性对应于 OnWebPartAdded 方法,此事件处理的基本模式适用于大多数 Web 部件事件及其关联的方法。

此外, WebPartManager 控件具有特定的方法,用于管理 WebPart 控件 (和用作 WebPart 控件) 的服务器或用户控件的任务。 这些方法包括 AddWebPart、、AuthorizeWebPartCloseWebPartCopyWebPartCreateWebPartEndWebPartEditingExportWebPartDeleteWebPartDisconnectWebPartBeginWebPartEditingGetGenericWebPartImportWebPart、、、 IsAuthorized和 。MoveWebPart

另一组方法专用于连接。 这包括诸如 、、CreateAvailableTransformersBeginWebPartConnectingDisconnectWebPartsDisconnectWebPartConnectWebPartsCanConnectWebPartsEndWebPartConnectingGetConsumerConnectionPointsGetProviderConnectionPointsActivateConnections方法。

最后,某些 WebPartManager 方法侧重于个性化功能。 它们包括 CreatePersonalizationLoadControlStateSaveCustomPersonalizationStateSetPersonalizationDirtyIPersonalizable.LoadIPersonalizable.SaveSaveControlState

有关可通过 Internals 属性访问的其他WebPartManager方法的详细信息,请参阅 类的文档WebPartManagerInternals

继承者说明

控件 WebPartManager 旨在进行扩展。 由于它是 Web 部件应用程序的核心,因此,当你想要扩展 Web 部件控件集中的某些特定类型或控件时,在许多情况下,还必须扩展 WebPartManager 类,因为它可能具有使自定义类型在 Web 部件应用程序的上下文中工作所需的一些属性或方法。 Web 部件参考文档 (请参阅 System.Web.UI.WebControls.WebParts) ,在讨论如何扩展 Web 部件类型时,经常提到扩展类需要执行的操作 WebPartManager ,或在代码示例中演示如何扩展该类。

构造函数

WebPartManager()

初始化 WebPartManager 类的新实例。

字段

BrowseDisplayMode

表示包含 Web 部件控件的页的默认显示模式。 此字段为只读。

CatalogDisplayMode

表示用于从控件目录向网页添加服务器控件的显示模式。 此字段为只读。

ConnectDisplayMode

表示用于显示特殊用户界面 (UI) 以便用户管理 WebPart 控件之间的连接的显示模式。 此字段为只读。

DesignDisplayMode

表示用于更改包含 Web 部件控件的网页布局的显示模式。 此字段为只读。

EditDisplayMode

表示最终用户可在其中编辑和修改服务器控件的显示模式。 此字段为只读。

属性

Adapter

获取控件的浏览器特定适配器。

(继承自 Control)
AppRelativeTemplateSourceDirectory

获取或设置包含该控件的 PageUserControl 对象的应用程序相对虚拟目录。

(继承自 Control)
AvailableTransformers

获取 WebPartTransformer 对象的集合,这些对象可用于在服务器控件之间创建 Web 部件连接。

BindingContainer

获取包含该控件的数据绑定的控件。

(继承自 Control)
ChildControlsCreated

获取一个值,该值指示是否已创建服务器控件的子控件。

(继承自 Control)
ClientID

获取由 ASP.NET 生成的 HTML 标记的控件 ID。

(继承自 Control)
ClientIDMode

获取或设置用于生成 ClientID 属性值的算法。

(继承自 Control)
ClientIDSeparator

获取一个字符值,该值表示 ClientID 属性中使用的分隔符字符。

(继承自 Control)
CloseProviderWarning

获取或设置一个警告,用户关闭在连接中充当其他控件的提供者的控件时,会显示该警告。

Connections

获取对网页上所有当前连接的集合的引用。

Context

为当前 Web 请求获取与服务器控件关联的 HttpContext 对象。

(继承自 Control)
Controls

获取包含在网页的 WebPart 区域中并由 WebPartZoneBase 控件管理的所有 WebPartManager、服务器或用户控件的集合。

DataItemContainer

如果命名容器实现 IDataItemContainer,则获取对命名容器的引用。

(继承自 Control)
DataKeysContainer

如果命名容器实现 IDataKeysControl,则获取对命名容器的引用。

(继承自 Control)
DeleteWarning

获取或设置一个自定义警告消息,当最终用户删除一个控件时,将显示该消息。

DesignMode

获取一个值,该值指示是否正在使用设计图面上的一个控件。

(继承自 Control)
DisplayMode

获取或设置包含 Web 部件控件的网页的活动显示模式。

DisplayModes

获取与 WebPartManager 控件关联的所有显示模式的只读集合。

DynamicConnections

获取网页上当前存在的所有动态连接的集合。

EnableClientScript

获取或设置一个值,该值确定在包含 WebPartManager 控件的网页上是否启用了客户端脚本。

EnableTheming

获取一个值,该值指示网页启用了主题。

EnableViewState

获取或设置一个值,该值指示服务器控件是否向发出请求的客户端保持自己的视图状态以及它所包含的任何子控件的视图状态。

(继承自 Control)
Events

获取控件的事件处理程序委托列表。 此属性为只读。

(继承自 Control)
ExportSensitiveDataWarning

获取或设置在用户尝试从 WebPart 控件导出敏感状态数据时显示的警告消息的文本。

HasChildViewState

获取一个值,该值指示当前服务器控件的子控件是否具有任何已保存的视图状态设置。

(继承自 Control)
ID

获取或设置分配给服务器控件的编程标识符。

(继承自 Control)
IdSeparator

获取用于分隔控件标识符的字符。

(继承自 Control)
Internals

获取对 WebPartManagerInternals 类的引用,该类用于合并和拆分实际在 WebPartManager 类中实现的,但通常对控件开发人员很有用的一组方法。

IsChildControlStateCleared

获取一个值,该值指示该控件中包含的控件是否具有控件状态。

(继承自 Control)
IsCustomPersonalizationStateDirty

获取一个值,该值指示是否已进行了个性化设置更改,这些更改影响 WebPartManager 控件所控制的页级别个性化设置详细信息。

IsTrackingViewState

获取一个值,用于指示服务器控件是否会将更改保存到其视图状态中。

(继承自 Control)
IsViewStateEnabled

获取一个值,该值指示是否为该控件启用了视图状态。

(继承自 Control)
LoadViewStateByID

获取一个值,该值指示控件是否通过 ID 而不是索引参与加载其视图状态。

(继承自 Control)
MediumPermissionSet

获取仅允许 PermissionSet 权限和 Execution 权限的 Medium 对象。

MinimalPermissionSet

获取仅允许 PermissionSet 权限和 Execution 权限的 Minimal 对象。

NamingContainer

获取对服务器控件的命名容器的引用,此引用创建唯一的命名空间,以区分具有相同 ID 属性值的服务器控件。

(继承自 Control)
Page

获取对包含服务器控件的 Page 实例的引用。

(继承自 Control)
Parent

获取对页 UI 层次结构中服务器控件的父控件的引用。

(继承自 Control)
Personalization

获取对包含网页个性化设置数据的对象的引用。

RenderingCompatibility

获取一个值,该值指定呈现的 HTML 将与之兼容的 ASP.NET 版本。

(继承自 Control)
SelectedWebPart

获取对当前选择的用于编辑或用于创建与另一个控件的连接的 WebPart 或其他服务器控件的引用。

Site

获取容器信息,该容器在呈现于设计图面上时承载当前控件。

(继承自 Control)
SkinID

获取或设置一个空字符串 (""),使 WebPartManager 控件不能应用任何外观。

StaticConnections

获取对网页上所有定义为静态连接的 WebPartConnection 对象的集合的引用。

SupportedDisplayModes

获取特定网页上所有可用显示模式的只读集合。

TemplateControl

获取或设置对包含该控件的模板的引用。

(继承自 Control)
TemplateSourceDirectory

获取包含当前服务器控件的 PageUserControl 的虚拟目录。

(继承自 Control)
UniqueID

获取服务器控件的唯一的、以分层形式限定的标识符。

(继承自 Control)
ValidateRequestMode

获取或设置指示控件是否检查来自浏览器的客户端输入是否具有潜在危险值的值。

(继承自 Control)
ViewState

获取状态信息的字典,这些信息使您可以在同一页的多个请求间保存和还原服务器控件的视图状态。

(继承自 Control)
ViewStateIgnoresCase

获取一个值,该值指示 StateBag 对象是否不区分大小写。

(继承自 Control)
ViewStateMode

获取或设置此控件的视图状态模式。

(继承自 Control)
Visible

获取一个值,该值可使子控件可见。

WebParts

获取对网页上的 WebPart 控件所跟踪的所有 WebPartManager 控件的引用。

Zones

获取对网页上所有 WebPartZoneBase 区域的集合的引用。

方法

ActivateConnections()

激活网页上当前所有非活动连接。

AddedControl(Control, Int32)

在子控件添加到 Control 对象的 Controls 集合后调用。

(继承自 Control)
AddParsedSubObject(Object)

通知服务器控件,分析了一个元素(XML 或 HTML),并将该元素添加到服务器控件的 ControlCollection 对象中。

(继承自 Control)
AddWebPart(WebPart, WebPartZoneBase, Int32)

提供向网页添加 WebPart 控件的标准编程方法。

ApplyStyleSheetSkin(Page)

将页样式表中定义的样式属性应用到控件。

(继承自 Control)
BeginRenderTracing(TextWriter, Object)

开始输出数据的设计时追踪。

(继承自 Control)
BeginWebPartConnecting(WebPart)

开始连接两个 WebPart 控件的过程。

BeginWebPartEditing(WebPart)

开始 WebPart 控件的编辑过程。

BuildProfileTree(String, Boolean)

收集有关服务器控件的信息并将该信息发送到 Trace 属性,在启用页的跟踪功能时将显示该属性。

(继承自 Control)
CanConnectWebParts(WebPart, ProviderConnectionPoint, WebPart, ConsumerConnectionPoint)

当使用者和提供者控件有兼容接口且不需要 WebPart 对象时,请检查将参与连接的 WebPartTransformer 控件,以确定它们是否能够被连接。

CanConnectWebParts(WebPart, ProviderConnectionPoint, WebPart, ConsumerConnectionPoint, WebPartTransformer)

检查将参与连接的 WebPart 控件,以确定这些控件是否能够连接,并使用 WebPartTransformer 对象在不兼容的使用者和提供者之间创建连接。

CheckRenderClientScript()

检查发出请求的浏览器的功能,并检查 EnableClientScript 属性的值,以确定是否呈现客户端脚本。

ClearCachedClientID()

将缓存的 ClientID 值设置为 null

(继承自 Control)
ClearChildControlState()

删除服务器控件的子控件的控件状态信息。

(继承自 Control)
ClearChildState()

删除服务器控件的所有子控件的视图状态和控件状态信息。

(继承自 Control)
ClearChildViewState()

删除服务器控件的所有子控件的视图状态信息。

(继承自 Control)
ClearEffectiveClientIDMode()

将当前控件实例和任何子控件的 ClientIDMode 属性设置为 Inherit

(继承自 Control)
CloseWebPart(WebPart)

以不在网页上呈现,但可以重新打开的方式关闭 WebPart 控件。

ConnectWebParts(WebPart, ProviderConnectionPoint, WebPart, ConsumerConnectionPoint)

只使用对控件的引用和控件所指定的 WebPart 对象在两个 GenericWebPartConnectionPoint 控件之间创建连接。

ConnectWebParts(WebPart, ProviderConnectionPoint, WebPart, ConsumerConnectionPoint, WebPartTransformer)

使用对两个 WebPartGenericWebPart 控件的引用、它们的指定 ConnectionPoint 对象和一个 WebPartTransformer 对象在这两个控件之间创建连接。

CopyWebPart(WebPart)

由 Web 部件控件集用来创建 WebPart 或服务器控件的副本,以向网页中添加该控件。

CreateAvailableTransformers()

创建一组在网站配置文件中指定的转换器,并将它们添加到 AvailableTransformers 属性所引用的转换器的集合。

CreateChildControls()

由 ASP.NET 页框架调用,以通知服务器控件在准备回发或呈现时使用基于撰写的实现来创建其所包含任何子控件。

(继承自 Control)
CreateControlCollection()

返回网页上的 WebPartManager 控件所管理的所有控件的集合。 此类不能被继承。

CreateDisplayModes()

为 Web 部件应用程序创建由所有可能的显示模式组成的显示模式集。

CreateDynamicConnectionID()

获取一个唯一值,用于充当动态连接的 ID。

CreateDynamicWebPartID(Type)

为动态 WebPart 控件生成唯一 ID。

CreateErrorWebPart(String, String, String, String, String)

当加载或创建动态 WebPart 控件的尝试因某种原因失败时,创建插入页中并向最终用户显示的特殊控件。

CreatePersonalization()

返回一个个性化设置对象,该对象包含当前网页的用户个性化设置数据。

CreateWebPart(Control)

WebPart 对象包装一个不是 GenericWebPart 控件的服务器控件,以使该控件能具有 Web 部件的功能。

DataBind()

将数据源绑定到调用的服务器控件及其所有子控件。

(继承自 Control)
DataBind(Boolean)

将数据源绑定到调用的服务器控件及其所有子控件,同时可以选择引发 DataBinding 事件。

(继承自 Control)
DataBindChildren()

将数据源绑定到服务器控件的子控件。

(继承自 Control)
DeleteWebPart(WebPart)

永久地从网页中移除 WebPart 控件的动态实例。

DisconnectWebPart(WebPart)

移除要关闭或要从其所参与的连接中删除的 WebPart 或服务器控件。

DisconnectWebParts(WebPartConnection)

执行断开网页中连接的服务器控件的过程。

Dispose()

使服务器控件得以在从内存中释放之前执行最后的清理操作。

(继承自 Control)
EndRenderTracing(TextWriter, Object)

结束输出数据的设计时追踪。

(继承自 Control)
EndWebPartConnecting()

完成将 WebPart 控件连接到另一个控件的过程。

EndWebPartEditing()

完成编辑 WebPart 控件的过程。

EnsureChildControls()

确定服务器控件是否包含子控件。 如果不包含,则创建子控件。

(继承自 Control)
EnsureID()

为尚未分配标识符的控件创建标识符。

(继承自 Control)
Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
ExportWebPart(WebPart, XmlWriter)

创建包含服务器控件的状态和属性数据的 XML 说明文件。

FindControl(String)

在当前的命名容器中搜索带指定 id 参数的服务器控件。

(继承自 Control)
FindControl(String, Int32)

使用指定的 idpathOffset 参数(该参数有助于搜索)中指定的整数在当前命名容器中搜索服务器控件。 不应重写此版本的 FindControl 方法。

(继承自 Control)
Focus()

被重写以防止将焦点设置在 WebPartManager 控件上,因为该控件没有用户界面 (UI)。

GetConsumerConnectionPoints(WebPart)

检索 ConsumerConnectionPoint 对象的集合,这些对象可以作为来自如下服务器控件的连接点:该服务器控件正在作为 Web 部件连接中的使用者。

GetCurrentWebPartManager(Page)

检索对页上的 WebPartManager 控件的当前实例的引用。

GetDesignModeState()

获取控件的设计时数据。

(继承自 Control)
GetDisplayTitle(WebPart)

获取一个字符串,其中包含 DisplayTitle 控件的 WebPart 属性的值。

GetExportUrl(WebPart)

获取当用户尝试导出 WebPart 控件时包含在请求中的相对虚拟路径和查询字符串。

GetGenericWebPart(Control)

获取对 GenericWebPart 控件的实例的引用,该实例包含一个服务器控件。

GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetProviderConnectionPoints(WebPart)

检索 ProviderConnectionPoint 对象的集合,这些对象可作为来自如下服务器控件的连接点:该服务器控件正在作为 Web 部件连接中的提供者。

GetRouteUrl(Object)

获取与一组路由参数对应的 URL。

(继承自 Control)
GetRouteUrl(RouteValueDictionary)

获取与一组路由参数对应的 URL。

(继承自 Control)
GetRouteUrl(String, Object)

获取与一组路由参数以及某个路由名称对应的 URL。

(继承自 Control)
GetRouteUrl(String, RouteValueDictionary)

获取与一组路由参数以及某个路由名称对应的 URL。

(继承自 Control)
GetType()

获取当前实例的 Type

(继承自 Object)
GetUniqueIDRelativeTo(Control)

返回指定控件的 UniqueID 属性的前缀部分。

(继承自 Control)
HasControls()

确定服务器控件是否包含任何子控件。

(继承自 Control)
HasEvents()

返回一个值,该值指示是否为控件或任何子控件注册事件。

(继承自 Control)
ImportWebPart(XmlReader, String)

导入包含 WebPart 控件的状态和属性数据的 XML 说明文件,并将这些数据应用于控件。

IsAuthorized(Type, String, String, Boolean)

执行确定控件是否已经过授权可添加至页的最后步骤。

IsAuthorized(WebPart)

执行确定控件是否被授权添加到页中的初始步骤。

IsLiteralContent()

确定服务器控件是否只包含文字内容。

(继承自 Control)
LoadControlState(Object)

加载从前一个页请求保存并需要在后续请求上还原的控件状态数据。

LoadCustomPersonalizationState(PersonalizationDictionary)

存储由个性化对象传递给 WebPartManager 控件的自定义个性化数据,稍后会将其用于初始化过程中。

LoadViewState(Object)

从用 SaveViewState() 方法保存的上一个页面请求还原视图状态信息。

(继承自 Control)
MapPathSecure(String)

检索虚拟路径(绝对的或相对的)映射到的物理路径。

(继承自 Control)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
MoveWebPart(WebPart, WebPartZoneBase, Int32)

WebPart 或服务器控件从一个 WebPartZoneBase 区域移动到另一个区域,或移动到相同区域中的新位置。

OnAuthorizeWebPart(WebPartAuthorizationEventArgs)

引发 AuthorizeWebPart 事件并调用该事件的处理程序(如果存在)。

OnBubbleEvent(Object, EventArgs)

确定服务器控件的事件是否沿页的 UI 服务器控件层次结构向上传递。

(继承自 Control)
OnConnectionsActivated(EventArgs)

引发 ConnectionsActivated 事件以指示已加载页及其控件,并且已激活页上的连接,可以开始共享数据。

OnConnectionsActivating(EventArgs)

引发 ConnectionsActivating 事件以指示已加载页及其控件,可以开始激活连接的过程。

OnDataBinding(EventArgs)

引发 DataBinding 事件。

(继承自 Control)
OnDisplayModeChanged(WebPartDisplayModeEventArgs)

引发 DisplayModeChanged 事件,以指示 WebPartManager 控件在网页上已完成从一种显示模式切换到另一种显示模式的过程。

OnDisplayModeChanging(WebPartDisplayModeCancelEventArgs)

引发 DisplayModeChanging 事件,以指示 WebPartManager 控件在网页上正处于从一种显示模式切换到另一种显示模式的过程中。

OnInit(EventArgs)

引发 Init 事件,该事件是 WebPartManager 控件生命周期中的第一个事件。

OnLoad(EventArgs)

引发 Load 事件。

(继承自 Control)
OnPreRender(EventArgs)

引发 PreRender 事件,该事件恰好在 WebPartManager 控件被呈现在网页上之前发生。

OnSelectedWebPartChanged(WebPartEventArgs)

引发 SelectedWebPartChanged 事件,该事件在新选择了某个 WebPart 控件或清除对它的选择之后发生。

OnSelectedWebPartChanging(WebPartCancelEventArgs)

引发 SelectedWebPartChanging 事件,该事件在更改当前选择的 WebPart 控件的过程中发生。

OnUnload(EventArgs)

引发基 Unload 事件,并从网页中移除 WebPartManager 实例。

OnWebPartAdded(WebPartEventArgs)

引发 WebPartAdded 事件,该事件在 WebPart 控件已被添加到某个页之后发生。

OnWebPartAdding(WebPartAddingEventArgs)

引发 WebPartAdding 事件,该事件将在向 WebPart 区域添加 WebPartZoneBase 控件(或服务器控件,或用户控件)的过程中发生。

OnWebPartClosed(WebPartEventArgs)

引发 WebPartClosed 事件以表明控件已从页中移除。

OnWebPartClosing(WebPartCancelEventArgs)

引发 WebPartClosing 事件,该事件将在从页中移除 WebPart 或服务器控件的过程中发生。

OnWebPartDeleted(WebPartEventArgs)

引发 WebPartDeleted 事件,该事件在从页中永久删除 WebPart 控件之后发生。

OnWebPartDeleting(WebPartCancelEventArgs)

引发 WebPartDeleting 事件,该事件指示动态 WebPart 控件(或 WebPartZoneBase 区域中包含的服务器控件或用户控件)正处于被删除的过程中。

OnWebPartMoved(WebPartEventArgs)

引发 WebPartMoved 事件,该事件在 WebPart 控件已被移动到页上的不同位置之后发生。

OnWebPartMoving(WebPartMovingEventArgs)

引发 WebPartMoving 事件,该事件指示 WebPart 区域中的 WebPartZoneBase、服务器控件或用户控件正处于移动过程中。

OnWebPartsConnected(WebPartConnectionsEventArgs)

引发 WebPartsConnected 事件,该事件在 WebPart 控件之间建立了连接之后发生。

OnWebPartsConnecting(WebPartConnectionsCancelEventArgs)

引发 WebPartsConnecting 事件,该事件发生于在 WebPart 区域内包含的两个 WebPartZoneBase 或服务器控件或用户控件之间建立连接的过程中。

OnWebPartsDisconnected(WebPartConnectionsEventArgs)

引发 WebPartsDisconnected 事件,该事件在 WebPart 控件之间的连接已终止之后发生。

OnWebPartsDisconnecting(WebPartConnectionsCancelEventArgs)

引发 WebPartsDisconnecting 事件,该事件指示 WebPart 区域中的两个 WebPartZoneBase 或服务器控件或用户控件正处于结束连接的过程中。

OpenFile(String)

获取用于读取文件的 Stream

(继承自 Control)
RaiseBubbleEvent(Object, EventArgs)

将所有事件源及其信息分配给控件的父级。

(继承自 Control)
RegisterClientScript()

使 WebPartManager 控件能够发出用于各种个性化设置功能(例如,在网页中拖动 WebPart 控件)的客户端脚本。

RemovedControl(Control)

Control 对象的 Controls 集合移除子控件后调用。

(继承自 Control)
Render(HtmlTextWriter)

重写以防止 WebPartManager 控件呈现任何内容。

RenderChildren(HtmlTextWriter)

将服务器控件子级的内容输出到提供的 HtmlTextWriter 对象,该对象可写入要在客户端上呈现的内容。

(继承自 Control)
RenderControl(HtmlTextWriter)

将服务器控件内容输出到所提供的 HtmlTextWriter 对象,如果启用了跟踪,则还将存储有关该控件的跟踪信息。

(继承自 Control)
RenderControl(HtmlTextWriter, ControlAdapter)

使用提供的 HtmlTextWriter 对象将服务器控件内容输出到提供的 ControlAdapter 对象。

(继承自 Control)
ResolveAdapter()

获取负责呈现指定控件的控件适配器。

(继承自 Control)
ResolveClientUrl(String)

获取浏览器可以使用的 URL。

(继承自 Control)
ResolveUrl(String)

将 URL 转换为在请求客户端可用的 URL。

(继承自 Control)
SaveControlState()

保存 WebPartManager 控件的状态数据,以便在将来请求包含该控件的网页时可以还原这些数据。

SaveCustomPersonalizationState(PersonalizationDictionary)

保存由 WebPartManager 控件维护的自定义个性化设置状态数据,以便重新加载该页时可以重新加载此数据。

SaveViewState()

保存将页面回发到服务器之后发生的所有服务器控件视图状态更改。

(继承自 Control)
SetDesignModeState(IDictionary)

为控件设置设计时数据。

(继承自 Control)
SetPersonalizationDirty()

设置一个标志,该标志指示 WebPartManager 控件的自定义个性化设置数据已更改。

SetRenderMethodDelegate(RenderMethod)

分配事件处理程序委托,以将服务器控件及其内容呈现到父控件中。

(继承自 Control)
SetSelectedWebPart(WebPart)

SelectedWebPart 属性值设置为等于当前选定的 WebPart 或服务器控件。

SetTraceData(Object, Object)

使用跟踪数据键和跟踪数据值,为呈现数据的设计时追踪设置跟踪数据。

(继承自 Control)
SetTraceData(Object, Object, Object)

使用跟踪对象、跟踪数据键和跟踪数据值,为呈现数据的设计时追踪设置跟踪数据。

(继承自 Control)
ToString()

返回表示当前对象的字符串。

(继承自 Object)
TrackViewState()

将个性化设置状态数据应用到 WebPartManager 控件,调用基方法以便能够跟踪对控件视图状态数据的更改。

事件

AuthorizeWebPart

当调用 IsAuthorized 方法以确定 WebPart 或服务器控件是否能够添加到页中时发生。

ConnectionsActivated

在页上的所有当前 Web 部件连接不仅已经连接,而且已经开始在每个连接所涉及的使用者控件和提供者控件之间共享数据之后发生。

ConnectionsActivating

在激活网页上所有已建立的 Web 部件连接的过程中发生。

DataBinding

当服务器控件绑定到数据源时发生。

(继承自 Control)
DisplayModeChanged

当 Web 部件页上的当前显示模式更改之后发生。

DisplayModeChanging

当用户单击网页上的谓词以启动不同显示模式之间的更改过程之后发生。

Disposed

当从内存释放服务器控件时发生,这是请求 ASP.NET 页时服务器控件生存期的最后阶段。

(继承自 Control)
Init

当服务器控件初始化时发生;初始化是控件生存期的第一步。

(继承自 Control)
Load

当服务器控件加载到 Page 对象中时发生。

(继承自 Control)
PreRender

在加载 Control 对象之后、呈现之前发生。

(继承自 Control)
SelectedWebPartChanged

在对一个 WebPart 控件的选择已经发生更改并被移动到网页上的另一个控件之后发生。

SelectedWebPartChanging

在更改网页上 WebPart 或服务器控件当前的选定状态的过程中发生。

Unload

当服务器控件从内存中卸载时发生。

(继承自 Control)
WebPartAdded

在动态 WebPart 或其他服务器控件已被添加到 WebPartZoneBase 区域之后发生,以指示已成功添加了控件。

WebPartAdding

在向 WebPart 区域添加动态 WebPartZoneBase 或其他服务器控件的过程中发生。

WebPartClosed

当从页中移除 WebPart 控件(或服务器控件,或用户控件)时发生。

WebPartClosing

在从页中移除 WebPart 控件(或服务器控件,或用户控件)的过程中发生。

WebPartDeleted

WebPart 或其他服务器控件已从 WebPartZoneBase 区域删除之后发生。

WebPartDeleting

在从 WebPart 区域中永久删除动态 WebPartZoneBase 或其他服务器控件的实例的过程中发生。

WebPartMoved

WebPart 或服务器控件已被移动到网页上的不同位置之后发生。

WebPartMoving

在移动 WebPart 区域中包含的 WebPartZoneBase 或其他服务器控件的过程中发生。

WebPartsConnected

WebPart 控件(或者服务器或用户控件)之间已建立特定连接之后发生。

WebPartsConnecting

在创建 WebPart 控件(或放置在 WebPartZoneBase 区域中的服务器控件或用户控件)之间的连接的过程中发生。

WebPartsDisconnected

在两个 WebPart 或服务器控件之间的连接已终止之后发生。

WebPartsDisconnecting

在结束以前连接的 WebPart 或服务器控件之间的连接的过程中发生。

显式接口实现

IControlBuilderAccessor.ControlBuilder

有关此成员的说明,请参见 ControlBuilder

(继承自 Control)
IControlDesignerAccessor.GetDesignModeState()

有关此成员的说明,请参见 GetDesignModeState()

(继承自 Control)
IControlDesignerAccessor.SetDesignModeState(IDictionary)

有关此成员的说明,请参见 SetDesignModeState(IDictionary)

(继承自 Control)
IControlDesignerAccessor.SetOwnerControl(Control)

有关此成员的说明,请参见 SetOwnerControl(Control)

(继承自 Control)
IControlDesignerAccessor.UserData

有关此成员的说明,请参见 UserData

(继承自 Control)
IDataBindingsAccessor.DataBindings

有关此成员的说明,请参见 DataBindings

(继承自 Control)
IDataBindingsAccessor.HasDataBindings

有关此成员的说明,请参见 HasDataBindings

(继承自 Control)
IExpressionsAccessor.Expressions

有关此成员的说明,请参见 Expressions

(继承自 Control)
IExpressionsAccessor.HasExpressions

有关此成员的说明,请参见 HasExpressions

(继承自 Control)
IParserAccessor.AddParsedSubObject(Object)

有关此成员的说明,请参见 AddParsedSubObject(Object)

(继承自 Control)
IPersonalizable.IsDirty

获取一个值,该值指示 WebPartManager 控件管理的自定义个性化设置状态数据是否已在网页上更改。

IPersonalizable.Load(PersonalizationDictionary)

返回先前保存的需要加载到 WebPartManager 控件的自定义个性化状态数据。

IPersonalizable.Save(PersonalizationDictionary)

保存由 WebPartManager 控件管理的自定义个性化设置状态数据。

扩展方法

FindDataSourceControl(Control)

返回与指定控件的数据控件关联的数据源。

FindFieldTemplate(Control, String)

返回指定控件的命名容器中指定列的字段模板。

FindMetaTable(Control)

返回包含数据控件的元表对象。

GetDefaultValues(INamingContainer)

为指定数据控件获取默认值的集合。

GetMetaTable(INamingContainer)

为指定数据控件获取表元数据。

SetMetaTable(INamingContainer, MetaTable)

为指定数据控件设置表元数据。

SetMetaTable(INamingContainer, MetaTable, IDictionary<String,Object>)

为指定数据控件设置表元数据和默认值映射。

SetMetaTable(INamingContainer, MetaTable, Object)

为指定数据控件设置表元数据和默认值映射。

TryGetMetaTable(INamingContainer, MetaTable)

确定表元数据是否可用。

EnableDynamicData(INamingContainer, Type)

为指定数据控件启用动态数据行为。

EnableDynamicData(INamingContainer, Type, IDictionary<String,Object>)

为指定数据控件启用动态数据行为。

EnableDynamicData(INamingContainer, Type, Object)

为指定数据控件启用动态数据行为。

适用于

另请参阅