WebPartDisplayModeとは? わかりやすく解説

WebPartDisplayMode クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

Web パーツ ページ使用できる複数表示モードに共通のプロパティ セット定義します

名前空間: System.Web.UI.WebControls.WebParts
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public MustInherit Class
 WebPartDisplayMode
Dim instance As WebPartDisplayMode
public abstract class WebPartDisplayMode
public ref class WebPartDisplayMode abstract
public abstract class WebPartDisplayMode
public abstract class WebPartDisplayMode
解説解説

Web パーツ ページは、複数異な表示モード使用できます。各表示モードは、Web パーツユーザー インターフェイス (UI) の特定の要素が非表示または表示となるか、およびページ対すユーザー特定の種類変更が有効または無効となるかが変わります。WebPartManager コントロールは、Web パーツ コントロール セット使用できる表示モード実装格納しページ表示モード管理します

使用できる表示モードを表すフィールドの一覧を次の表に示します

継承時の注意 開発者は、WebPartDisplayMode クラスから派生させて、カスタム表示モード作成できますカスタム WebPartDisplayModeWeb パーツ ページ上で使用できるようにするには、WebPartManager クラスから派生させ、その CreateDisplayModes メソッドオーバーライドする必要もあります

使用例使用例

表示モードWeb パーツ ページ上で宣言によって使用するコード例次に示します。各表示モードWeb パーツ コントロール セットにより実装されていて、WebPartDisplayMode クラスから派生します。

このコード例は、4 つ部分構成されます。

この例の最初部分は、カスタム WebPart コントロール TextDisplayWebPart です。コード例実行するためには、このソース コードコンパイルする必要があります。それを明示的にコンパイルし、コンパイル済みアセンブリWeb サイトBin フォルダまたはグローバル アセンブリ キャッシュ配置できますサイトの App_Code フォルダソース コード配置し実行時動的にコンパイルすることもできます両方コンパイル方法例については、「チュートリアル : カスタム サーバー コントロール開発と使用」を参照してください

Imports System
Imports System.Security.Permissions
Imports System.Web
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 Class TextDisplayWebPart
    Inherits WebPart
    Private _contentText As String
 = Nothing
    Private input As TextBox
    Private DisplayContent As Label
    
    
    Public Sub New() 
      Me.AllowClose = False
    End Sub
    
    <Personalizable(), WebBrowsable()>  _
    Public Property ContentText() As
 String 
        Get
            Return _contentText
        End Get
        Set
            _contentText = value
        End Set
    End Property
     
    Protected Overrides Sub
 CreateChildControls() 
        Controls.Clear()
        DisplayContent = New Label()
        DisplayContent.Text = Me.ContentText
        DisplayContent.BackColor = _
          System.Drawing.Color.LightBlue
        Me.Controls.Add(DisplayContent)
        input = New TextBox()
        Me.Controls.Add(input)
        Dim update As New
 Button()
        update.Text = "Set Label Content"
        AddHandler update.Click, AddressOf
 Me.submit_Click
        Me.Controls.Add(update)
        ChildControlsCreated = True
    
    End Sub
    
    
    Private Sub submit_Click(ByVal
 sender As Object, _
                             ByVal e As EventArgs)
 
        ' Update the label string.
        If input.Text <> String.Empty
 Then
            Me.ContentText = Page.Server.HtmlEncode(input.Text)
 + "<br />"
            ' Clear the input textbox.
            input.Text = String.Empty
            DisplayContent.Text = Me.ContentText
        End If
    
    End Sub
    
End Class

End Namespace
using System;
using System.Security.Permissions;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace Samples.AspNet.CS.Controls
{
  [AspNetHostingPermission(SecurityAction.Demand, 
    Level=AspNetHostingPermissionLevel.Minimal)]
  [AspNetHostingPermission(SecurityAction.InheritanceDemand, 
    Level=AspNetHostingPermissionLevel.Minimal)]
  public class TextDisplayWebPart : WebPart
  {
    private String _contentText = null;
    TextBox input;
    Label DisplayContent;
    const string _subTitle = "Contoso,
 Ltd";

    public TextDisplayWebPart()
    {
      this.AllowClose = false;
    }

    [
      Personalizable(PersonalizationScope.User, true),
      WebBrowsable()
    ]
    public String ContentText
    {
      get { return _contentText; }
      set { _contentText = value; }
    }

    protected override void CreateChildControls()
    {
      Controls.Clear();
      DisplayContent = new Label();
      DisplayContent.BackColor = 
        System.Drawing.Color.LightBlue;
      DisplayContent.Text = this.ContentText;
      this.Controls.Add(DisplayContent);
      input = new TextBox();
      this.Controls.Add(input);
      Button update = new Button();
      update.Text = "Set Label Content";
      update.Click += new EventHandler(this.submit_Click);
      this.Controls.Add(update);
      ChildControlsCreated = true;
    }

    private void submit_Click(object sender,
 EventArgs e)
    {
      // Update the label string.
      if (input.Text != String.Empty)
      {
        this.ContentText = Page.Server.HtmlEncode(input.Text)
 + @"<br />";
        // Clear the input textbox.
        input.Text = String.Empty;
        DisplayContent.Text = this.ContentText;
      }
    }
  }
}

コード例2 番目の部分は、<asp:webpartzone> 要素内で ASP.NET 標準Calendar コントロール参照する Web ページで、コントロールは GenericWebPart コントロールラップされ、実行時Web パーツ基本機能与えられます。また、このページでは <asp:catalogzone> 要素内で TextDisplayWebPart コントロール参照してエンドユーザーカタログ モード切り替えてコントロールページ追加できるようにする機能示してます。このページには <asp:editorzone> 要素含まれています。これにより、ユーザーページ編集モード場合<asp:webpartzone>格納されているコントロール編集できるようになりますページの上部には、カスタム コントロール用の register ディレクティブと、ユーザー コントロール用のディレクティブ含まれています。

<%@ page language="VB" %>
<%@ register TagPrefix="uc1" 
  TagName="DisplayModeMenuVB" 
  Src="DisplayModeMenuVB.ascx" %>
<%@ register tagprefix="aspSample" 
  Namespace="Samples.AspNet.VB.Controls"
 
  Assembly="TextDisplayWebPartVB"%>
<script runat="server">
Sub Button1_Click(Byval sender As
 Object, _
                  ByVal e As EventArgs)
  WebPartManager1.DisplayMode = WebPartManager.CatalogDisplayMode
End Sub
</script>
<html>
<head id="Head1" runat="server">
  <title>Web Parts Display Modes</title>
</head>
<body>
  <form id="Form2" runat="server">
    <asp:webpartmanager id="WebPartManager1" runat="server"
 />
    <uc1:DisplayModeMenuVB ID="DisplayModeMenu1"
 runat="server" />
    <asp:webpartzone
      id="WebPartZone1"
      runat="server" BackImageUrl="~/MyImage.gif">
        <zonetemplate>
          <asp:Calendar 
            ID="Calendar1" 
            Runat="server" 
            Title="My Calendar" />
        </zonetemplate>
    </asp:webpartzone>
    <asp:WebPartZone ID="WebPartZone2" Runat="server">
    </asp:WebPartZone>
    <asp:EditorZone ID="editzone1" Runat="server">
      <ZoneTemplate>
        <asp:AppearanceEditorPart 
          ID="appearanceeditor1" 
          Runat="server" />
        <asp:LayoutEditorPart 
          ID="LayoutEditorPart1" 
          Runat="server" />
      </ZoneTemplate>
    </asp:EditorZone>
    <asp:CatalogZone ID="catalogzone1" Runat="server">
      <ZoneTemplate>
        <asp:DeclarativeCatalogPart 
          ID="declarativepart1" 
          Runat="server">
          <WebPartsTemplate>
          <aspSample:TextDisplayWebPart 
            runat="server"   
            id="textwebpart" 
            title = "Text Content WebPart"/>  
          </WebPartsTemplate>
        </asp:DeclarativeCatalogPart>
      </ZoneTemplate>
    </asp:CatalogZone>
    <br />
    <asp:button
      id="button1"
      runat="server"
      text="Catalog Mode"
      OnClick="Button1_Click"
    />
  </form>
</body>
</html>
<%@ page language="C#" %>
<%@ register TagPrefix="uc1" 
  TagName="DisplayModeMenuCS" 
  Src="DisplayModeMenuCS.ascx" %>
<%@ register tagprefix="aspSample" 
  Namespace="Samples.AspNet.CS.Controls" 
  Assembly="TextDisplayWebPartCS"%>
<script runat="server">
void Button1_Click(object sender, EventArgs e)
{
  WebPartManager1.DisplayMode = WebPartManager.CatalogDisplayMode;
}
</script>
<html>
<head id="Head1" runat="server">
  <title>Web Parts Display Modes</title>
</head>
<body>
  <form id="Form2" runat="server">
    <asp:webpartmanager id="WebPartManager1" runat="server"
 />
    <uc1:DisplayModeMenuCS ID="DisplayModeMenu1" runat="server"
 />
    <asp:webpartzone
      id="WebPartZone1"
      runat="server" BackImageUrl="~/MyImage.gif">
        <zonetemplate>
          <asp:Calendar 
            ID="Calendar1" 
            Runat="server" 
            Title="My Calendar" />
        </zonetemplate>
    </asp:webpartzone>
    <asp:WebPartZone ID="WebPartZone2" Runat="server">
    </asp:WebPartZone>
    <asp:EditorZone ID="editzone1" Runat="server">
      <ZoneTemplate>
        <asp:AppearanceEditorPart 
          ID="appearanceeditor1" 
          Runat="server" />
        <asp:LayoutEditorPart 
          ID="LayoutEditorPart1" 
          Runat="server" />
      </ZoneTemplate>
    </asp:EditorZone>
    <asp:CatalogZone ID="catalogzone1" Runat="server">
      <ZoneTemplate>
        <asp:DeclarativeCatalogPart 
          ID="declarativepart1" 
          Runat="server">
          <WebPartsTemplate>
          <aspSample:TextDisplayWebPart 
            runat="server"   
            id="textwebpart" 
            title = "Text Content WebPart" AllowClose="true"/>
  
          </WebPartsTemplate>
        </asp:DeclarativeCatalogPart>
      </ZoneTemplate>
    </asp:CatalogZone>
    <br />
    <asp:button
      id="button1"
      runat="server"
      text="Catalog Mode"
      OnClick="Button1_Click"
    />
  </form>
</body>
</html>

コード例3 番目の部分は、ユーザーWeb ページ上の表示モード切り替えられるようにするユーザー コントロールです。このコントロールソース コードを、(コード例使用する言語に応じて) DisplayModeMenuCS.ascx または DisplayModeMenuVB.ascx という名前のファイル保存しWeb ページと同じディレクトリ配置します表示モード詳細、およびこのコントロールソース コード説明については、「チュートリアル : Web パーツ ページでの表示モード変更」を参照してください

<%@ 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="&nbsp;Display Mode" 
      Font-Bold="true"
      Font-Size="8"
      Width="120" />
    <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="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="&nbsp;Display Mode" 
      Font-Bold="true"
      Font-Size="8"
      Width="120" />
    <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>

ブラウザページ読み込む場合、[Display Mode] ドロップダウン リスト コントロール使用して異な表示モード切り替えることができますコントロール編集するには、ドロップダウン リスト コントロールで [編集] をクリックします。特定のコントロール編集するには、コントロールタイトル バー矢印クリックして動詞メニュー表示し動詞メニューで [編集] をクリックします。コントロール編集モード場合編集コントロールページ追加され編集するコントロール外観およびレイアウト変更できるようになります終了する場合は、[Display Mode] ドロップダウン リスト コントロールの [参照] をクリックしてページ既定表示戻しますページコントロール追加するには、カタログ モード切り替えます。[Display Mode] ドロップダウン リスト コントロール使用するか、ページの下の方にあるボタンクリックできます表示モードプログラムによって変更する方法を、Button1_Click メソッドインライン コード示しますカタログ モード場合には、カスタム TextDisplayWebPart コントロールページ追加できます

継承階層継承階層
System.Object
  System.Web.UI.WebControls.WebParts.WebPartDisplayMode
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

WebPartDisplayMode コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

表示モードの名前の値を初期化します。

名前空間: System.Web.UI.WebControls.WebParts
アセンブリ: System.Web (system.web.dll 内)
構文構文

Dim name As String

Dim instance As New WebPartDisplayMode(name)
protected WebPartDisplayMode (
    string name
)
protected:
WebPartDisplayMode (
    String^ name
)
protected WebPartDisplayMode (
    String name
)
protected function WebPartDisplayMode (
    name : String
)

パラメータ

name

表示モードの名前。

例外例外
例外種類条件

ArgumentNullException

name パラメータnull 参照 (Visual Basic では Nothing) です。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
WebPartDisplayMode クラス
WebPartDisplayMode メンバ
System.Web.UI.WebControls.WebParts 名前空間
その他の技術情報
ASP.NET Web パーツ ページ

WebPartDisplayMode プロパティ


WebPartDisplayMode メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

WebPartDisplayMode メンバ

Web パーツ ページ使用できる複数表示モードに共通のプロパティ セット定義します

WebPartDisplayMode データ型公開されるメンバを以下の表に示します


プロテクト コンストラクタプロテクト コンストラクタ
  名前 説明
プロテクト メソッド WebPartDisplayMode 表示モードの名前の値を初期化します。
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からWebPartDisplayModeを検索した結果を表示しています。
Weblioに収録されているすべての辞書からWebPartDisplayModeを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からWebPartDisplayMode を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「WebPartDisplayMode」の関連用語

WebPartDisplayModeのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



WebPartDisplayModeのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS