WebPartManager.BrowseDisplayMode 字段

定义

表示包含 Web 部件控件的页的默认显示模式。Represents the default display mode for pages that contain Web Parts controls. 此字段为只读。This field is read-only.

public: static initonly System::Web::UI::WebControls::WebParts::WebPartDisplayMode ^ BrowseDisplayMode;
public static readonly System.Web.UI.WebControls.WebParts.WebPartDisplayMode BrowseDisplayMode;
 staticval mutable BrowseDisplayMode : System.Web.UI.WebControls.WebParts.WebPartDisplayMode
Public Shared ReadOnly BrowseDisplayMode As WebPartDisplayMode 

字段值

WebPartDisplayMode

示例

下面的代码示例演示如何以编程方式使用 BrowseDisplayMode 字段。The following code example demonstrates how to work with the BrowseDisplayMode field programmatically. 此代码使用受支持的显示模式(在本例中为 "浏览" 和 "设计")填充下拉列表。The code populates a drop-down list with the supported display modes, which in this case are browse and design. 请注意,在 Page_PreRender 方法中,代码检查当前 DisplayMode 属性是否设置为 BrowseDisplayModeNotice that, in the Page_PreRender method, the code checks whether the current DisplayMode property is set to BrowseDisplayMode. 如果是这样,将 Label1 显示,如果不可见, Label1 将隐藏。If so, Label1 will be visible, and if not, Label1 will be hidden.

<%@ Page Language="C#" %>

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


  protected void Page_Init(object sender, EventArgs e)
  {
    foreach (WebPartDisplayMode mode in mgr1.SupportedDisplayModes)
    {
      string modeName = mode.Name;
      if (mode.IsEnabled(mgr1))
      {
        ListItem item = new ListItem(modeName, modeName);
        DisplayModeDropdown.Items.Add(item);
      }      
    }
  }

  protected void DisplayModeDropdown_SelectedIndexChanged(object 
    sender, EventArgs e)
  {
    String selectedMode = DisplayModeDropdown.SelectedValue;
    WebPartDisplayMode mode = 
      mgr1.SupportedDisplayModes[selectedMode];
    if (mode != null)
      mgr1.DisplayMode = mode;
  }

  protected void Page_PreRender(object sender, EventArgs e)
  {
    if (mgr1.DisplayMode == WebPartManager.BrowseDisplayMode)
      Label1.Visible = true;
    else
      Label1.Visible = false;
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:WebPartManager ID="mgr1" runat="server">
      </asp:WebPartManager>
      <asp:WebPartZone ID="WebPartZone1" runat="server">
        <ZoneTemplate>
          <asp:Calendar ID="Calendar1" runat="server" 
            Title="My Calendar" />
        </ZoneTemplate>
      </asp:WebPartZone>
      <asp:WebPartZone ID="WebPartZone2" runat="server">
        <ZoneTemplate>
          <asp:BulletedList 
            DisplayMode="HyperLink" 
            ID="BulletedList1" 
            runat="server"
            Title="My Links">
            <asp:ListItem Value="http://www.microsoft.com">
            Microsoft
            </asp:ListItem>
            <asp:ListItem Value="http://www.msn.com">
            MSN
            </asp:ListItem>
            <asp:ListItem Value="http://www.contoso.com">
            Contoso Corp.
            </asp:ListItem>
          </asp:BulletedList>
        </ZoneTemplate>
      </asp:WebPartZone>
      <hr />
      <asp:Label ID="Label1" runat="server" 
        Text="Currently in Browse Mode" 
        Font-Bold="true"
        Font-Size="125%" />
      <br />
      <asp:DropDownList ID="DisplayModeDropdown" runat="server" 
        AutoPostBack="true"
        Width="120"
        OnSelectedIndexChanged=
        "DisplayModeDropdown_SelectedIndexChanged">
      </asp:DropDownList>
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" %>

<!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 Page_Init(ByVal sender As Object, _
    ByVal e As EventArgs)
    Dim mode As WebPartDisplayMode
    For Each mode In mgr1.SupportedDisplayModes
      Dim modeName As String = mode.Name
      If mode.IsEnabled(mgr1) Then
        Dim item As ListItem = New ListItem(modeName, modeName)
        DisplayModeDropdown.Items.Add(item)
      End If
    Next
    
  End Sub

  Protected Sub DisplayModeDropdown_SelectedIndexChanged(ByVal _
    sender As Object, ByVal e As EventArgs)
    Dim selectedMode As String = _
      DisplayModeDropdown.SelectedValue
    Dim mode As WebPartDisplayMode = _
      mgr1.SupportedDisplayModes(selectedMode)
    If mode IsNot Nothing Then
      mgr1.DisplayMode = mode
    End If
  End Sub
  
  Protected Sub Page_PreRender(ByVal sender As Object, _
    ByVal e As System.EventArgs)
    If mgr1.DisplayMode.Equals(WebPartManager.BrowseDisplayMode) Then
      Label1.Visible = True
    Else
      Label1.Visible = False
    End If
  End Sub
</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">
    <div>
      <asp:WebPartManager ID="mgr1" runat="server">
      </asp:WebPartManager>
      <asp:WebPartZone ID="WebPartZone1" runat="server">
        <ZoneTemplate>
          <asp:Calendar ID="Calendar1" runat="server" 
            Title="My Calendar" />
        </ZoneTemplate>
      </asp:WebPartZone>
      <asp:WebPartZone ID="WebPartZone2" runat="server">
        <ZoneTemplate>
          <asp:BulletedList 
            DisplayMode="HyperLink" 
            ID="BulletedList1" 
            runat="server"
            Title="My Links">
            <asp:ListItem Value="http://www.microsoft.com">
            Microsoft
            </asp:ListItem>
            <asp:ListItem Value="http://www.msn.com">
            MSN
            </asp:ListItem>
            <asp:ListItem Value="http://www.contoso.com">
            Contoso Corp.
            </asp:ListItem>
          </asp:BulletedList>
        </ZoneTemplate>
      </asp:WebPartZone>
      <hr />
      <asp:Label ID="Label1" runat="server" 
        Text="Currently in Browse Mode" 
        Font-Bold="true"
        Font-Size="125%" />
      <br />
      <asp:DropDownList ID="DisplayModeDropdown" runat="server" 
        AutoPostBack="true"
        Width="120"
        OnSelectedIndexChanged=
        "DisplayModeDropdown_SelectedIndexChanged">
      </asp:DropDownList>
    </div>
    </form>
</body>
</html>

在浏览器中加载页面后,默认情况下处于浏览模式。After you load the page in a browser, you are in browse mode by default. 请注意页面上的标签,指示你处于浏览模式。Notice the label on the page that indicates you are in browse mode. 使用下拉列表控件将页面切换到设计模式。Use the drop-down list control to switch the page to design mode. 请注意,由于方法中的代码 Page_PreRender ,标签现在处于隐藏状态。Notice that, because of the code in the Page_PreRender method, the label is now hidden.

注解

BrowseDisplayMode字段引用由 WebPartDisplayMode 控件创建并包含的自定义对象 WebPartManagerThe BrowseDisplayMode field references a custom WebPartDisplayMode object that is created and contained by the WebPartManager control. 因为这是一个静态对象,所以可以直接通过类引用它, WebPartManager 而无需控件的实例。Because this is a static object, you can refer to it directly through the WebPartManager class without needing an instance of the control.

当包含 Web 部件控件的页面首次加载时,默认情况下,它处于 BrowseDisplayMode (浏览模式) 中。When a page that contains Web Parts controls first loads, it is in BrowseDisplayMode (browse mode) by default. 当用户只是在正常网页上浏览时,该页面仍处于浏览模式。When users are simply browsing as they would on a normal Web page, the page remains in browse mode. 如果用户想要对页面的布局、控件、外观或行为进行个性化设置,则必须将页面切换为通过属性提供的专用显示模式之一 SupportedDisplayModesIf users want to personalize a page's layout, controls, appearance, or behavior, they must switch the page into one of the specialized display modes available through the SupportedDisplayModes property.

适用于

另请参阅