WebPartManager.DesignDisplayMode Campo

Definição

Representa o modo de exibição usado para alterar o layout de páginas da Web que contenham controles de Web Parts.Represents the display mode used for changing the layout of Web pages that contain Web Parts controls. Este campo é somente leitura.This field is read-only.

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

Valor do campo

WebPartDisplayMode

Exemplos

O exemplo de código a seguir demonstra como trabalhar com o DesignDisplayMode campo programaticamente.The following code example demonstrates how to work with the DesignDisplayMode field programmatically. O código popula uma lista suspensa com os modos de exibição com suporte para a página, que nesse caso são Browse e design.The code populates a drop-down list with the supported display modes for the page, which in this case are browse and design. Observe que, no Page_PreRender método, o código verifica se a propriedade atual DisplayMode está definida como DesignDisplayMode .Notice that, in the Page_PreRender method, the code checks whether the current DisplayMode property is set to DesignDisplayMode. Nesse caso, Label1 ficará visível e, se não, Label1 será ocultado.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 mgr.SupportedDisplayModes)
    {
      string modeName = mode.Name;
      if (mode.IsEnabled(mgr))
      {
        ListItem item = new ListItem(modeName, modeName);
        DisplayModeDropdown.Items.Add(item);
      }      
    }
  }

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

  protected void Page_PreRender(object sender, EventArgs e)
  {
    if (mgr.DisplayMode == WebPartManager.DesignDisplayMode)
      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="mgr" 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 Design 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 mgr.SupportedDisplayModes
      Dim modeName As String = mode.Name
      If mode.IsEnabled(mgr) 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 = _
      mgr.SupportedDisplayModes(selectedMode)
    If mode IsNot Nothing Then
      mgr.DisplayMode = mode
    End If
  End Sub
  
  Protected Sub Page_PreRender(ByVal sender As Object, _
    ByVal e As System.EventArgs)
    If mgr.DisplayMode.Equals(WebPartManager.DesignDisplayMode) 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="mgr" 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 Design 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>

Depois de carregar a página em um navegador, você está no modo de procura por padrão.After you load the page in a browser, you are in browse mode by default. Observe que o rótulo na página está oculto.Notice that the label on the page is hidden. Use o controle lista suspensa para alternar a página para o modo de design.Use the drop-down list control to switch the page to design mode. Observe que, devido ao código no Page_PreRender método, o rótulo agora está visível.Notice that, because of the code in the Page_PreRender method, the label is now visible.

Comentários

O DesignDisplayMode campo faz referência a um WebPartDisplayMode objeto personalizado que é criado e contido no WebPartManager controle.The DesignDisplayMode field references a custom WebPartDisplayMode object that is created and contained by the WebPartManager control. Como esse é um objeto estático, você pode consultá-lo diretamente por meio da WebPartManager classe sem precisar de uma instância do controle.Because this is a static object, you can refer to it directly through the WebPartManager class without needing an instance of the control.

Quando uma página que contém Web Parts controles é carregada pela primeira vez, ela está no BrowseDisplayMode (modo de procura) por padrão.When a page that contains Web Parts controls first loads, it is in BrowseDisplayMode (browse mode) by default. Quando os usuários desejam alterar o layout da página movendo os controles para diferentes zonas ou dentro das zonas atuais, eles devem primeiro alternar a página para DesignDisplayMode (modo de Design).When users want to change the layout of the page by moving controls to different zones or within the current zones, they must first switch the page to DesignDisplayMode (design mode). No modo de design, a interface do usuário para as várias zonas é exibida e os usuários podem arrastar controles para alterar o layout.In design mode, the user interface (UI) for the various zones appears, and users can then drag controls to change the layout.

Aplica-se a

Confira também