CatalogZoneBase クラスとは? わかりやすく解説

CatalogZoneBase クラス

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

Web ページ追加できる WebPart コントロールリストを含むカタログとして機能するすべてのゾーン コントロール基本クラスとして機能します

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

Public MustInherit Class
 CatalogZoneBase
    Inherits ToolZone
    Implements IPostBackDataHandler
Dim instance As CatalogZoneBase
public abstract class CatalogZoneBase : ToolZone,
 IPostBackDataHandler
public ref class CatalogZoneBase abstract :
 public ToolZone, IPostBackDataHandler
public abstract class CatalogZoneBase extends
 ToolZone implements IPostBackDataHandler
public abstract class CatalogZoneBase extends
 ToolZone implements IPostBackDataHandler
解説解説

CatalogZoneBase クラスは、ToolZone クラスから継承する基本クラスで、ユーザーWeb ページ追加できるコントロールリストまたはカタログ提供する派生ゾーン動作基本セット提供します

CatalogZoneBase クラスは、一意ユーザー インターフェイス (UI) を提供しますエンド ユーザーは、この UI使用してWebPart コントロールおよび他のサーバー コントロール (ASP.NET サーバー コントロールユーザー コントロール、およびカスタム サーバー コントロールなど) を Web ページ追加できます。CatalogZone などの CatalogZoneBase クラスから派生するコントロールは、実際に Web ページ配置されるコントロールであり、CatalogPart コントロール呼ばれるその他のコントロールコンテナとして機能します。これらは、ユーザーページ追加するサーバー コントロールリスト作成しますCatalogZoneBase クラスから派生するゾーンは、ページカタログ表示モード場合だけに表示されます。

メモ重要 :

CatalogZoneBase ゾーンには、CatalogPart コントロールだけを含めることができます逆にいうと、CatalogPart コントロールは、CatalogZoneBase ゾーンだけに存在できます

サーバー コントロールへのカタログ追加には、基本 CatalogPart クラスから派生する 3 つのコントロールセット使用されます。3 つの CatalogPart コントロール次の表に示します

CatalogZoneBase クラスには、WebPart コントロールカタログ表示するのに便利なプロパティ多数あります。AddVerb プロパティは、カタログ内で選択したコントロールページ追加する動詞参照します。一方、CloseVerb プロパティは、カタログ閉じてページ表示モードブラウズ モードに戻す動詞参照します。CatalogParts プロパティは、ゾーン内のすべての CatalogPart コントロールコレクション参照します。EmptyZoneText、HeaderText、および InstructionText の各プロパティなどの複数テキスト指向プロパティは、基本プロパティオーバーライドしてカタログ合った既定テキスト提供します。SelectTargetZoneText プロパティは、ユーザーコントロール追加先のゾーン選択できるドロップダウン リスト コントロールの横に表示されるテキスト含みます

その他に複数プロパティCatalogZoneBase クラス含まれています。SelectedCatalogPartID プロパティは、現在選択されている CatalogPart コントロール一意文字列識別子です。ShowCatalogIcons プロパティは、WebPart コントロールの CatalogIconImageUrl プロパティ設定することによってコントロール関連付けることができるアイコン表示するかどうか示します

PartLinkStyle プロパティは、ゾーン内で現在選択されていない CatalogPart コントロールへのリンクのスタイル属性含みます。これに対して、SelectedPartLinkStyle プロパティは、ゾーン内でユーザーが現在選択している CatalogPart コントロールへのリンクのスタイル属性含みます

これらのプロパティ加えてCatalogZoneBase クラスには、他の基本コントロールか継承される標準イベント処理メソッドおよびレンダリング メソッド以外に、特にコントロールカタログ処理するためにデザインされているメソッド複数あります。CreateCatalogPartChrome メソッドは、ゾーン内で各 CatalogPart コントロールを囲むクロム (境界線動詞アイコンタイトルなどの周辺UI 要素) を作成しますまた、コントロールレンダリング処理します。CreateCatalogParts メソッドは、抽象メソッドであり、ゾーン含まれるすべての CatalogPart コントロールインスタンス作成するように、派生クラスオーバーライドされます。InvalidateCatalogParts メソッドは、ゾーン内の CatalogPart コントロールコレクション何らかのプログラム上の理由変更される場合に、派生クラスによって呼び出すことができます。このとき、派生クラスコレクション再作成する必要があります。LoadPostData メソッドは、ページサーバーポスト バックされるたびに、カタログWebPart コントロールの横のチェック ボックス用に、以前既存の状態を読み込みます。逆に、SaveControlState メソッドは、チェック ボックスの状態を保存します最後に、RenderCatalogPartLinks メソッドは、ゾーン含まれるCatalogPart コントロールへのリンクのすべてのレンダリング提供します

継承時の注意 CatalogPart コントロールホストするためにカスタム ゾーン開発する場合は、ゾーン テンプレートサポート提供するかどうか決定する必要がありますゾーン テンプレートは、ITemplate インターフェイス実装するタイプによって作成されます。また、カスタム ゾーン使用するページ開発者が、Web ページ宣言マークアップゾーン内の CatalogPart コントロール参照できるようにする場合は、このゾーン テンプレートが必要です。ゾーン テンプレートサポート必要な場合は、CatalogZone クラスから継承する必要があります。これに対してカスタム ゾーンとその CatalogPart コントロール単体使用できるようにする場合で、これらをプログラム作成するときにゾーン テンプレート宣言によってページ開発者コントロール指定するオプション含めない場合は、CatalogZoneBase クラスから直接継承できますCatalogZoneBase クラスから継承する場合は、CreateCatalogParts メソッドオーバーライドし、カタログ含めWebPart またはその他のサーバー コントロールを CatalogPartCollection オブジェクト追加する必要があります

使用例使用例

CatalogZoneBase クラスの宣言およびプログラムでの複数使用を示すコード例次に示します。これは抽象クラスのため、コード例では、Web パーツ コントロール セット付属する派生 CatalogZone クラス使用しますまた、CatalogZoneBase クラスから継承するプロパティおよびメソッドデモンストレーションます。

コード例は、次の 4 つ部分から成ります

コード例最初部分は、ページ上の表示モード変更できるようにするユーザー コントロールです。表示モード詳細、およびこのコントロールソース コード説明については、「チュートリアル : 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>

コード例2 番目の部分は、CatalogZone コントロールへの宣言参照を含む Web ページです。ページ先頭近くに、2 つRegister ディレクティブあります1 つユーザー コントロール用、もう 1 つカスタム WebPart コントロール用です。<asp:WebPartZone> 要素の下には、カスタムWebPart コントロールおよび ASP.NET Calendar コントロールへの宣言参照を含む <asp: CatalogZone> 要素ありますゾーンには、その外観および動作指定するために設定されるさまざまなタグおよびプロパティありますページ<script> タグ間には、さまざまなイベント処理コードがあり、そのほとんどは、CatalogZoneBase メンバプログラムによるさまざまな使用示します

<%@ page language="vb" %>
<%@ register TagPrefix="uc1" 
  TagName="DisplayModeMenuVB" 
  Src="DisplayModeMenuvb.ascx" %>
<%@ register tagprefix="aspSample" 
  Namespace="Samples.AspNet.VB.Controls"
 
  Assembly="TextDisplayWebPartVB"
 %>
  
<script runat="server">


  Dim manager As WebPartManager


  Protected Sub WebPartManager1_DisplayModeChanged(ByVal
 sender _
    As Object, ByVal e As
 WebPartDisplayModeEventArgs)
    If e.OldDisplayMode.Name <> "Catalog"
 Then
      Panel1.Visible = True
    Else
      Panel1.Visible = False
    End If

  End Sub
   
  Protected Sub Button1_Click(ByVal
 sender As Object, _
    ByVal e As EventArgs)
    If CatalogZone1.AddVerb.Enabled Then
      CatalogZone1.AddVerb.Enabled = False
      CatalogZone1.CloseVerb.Enabled = False
    Else
      CatalogZone1.AddVerb.Enabled = True
      CatalogZone1.CloseVerb.Enabled = True
    End If

  End Sub
  
  Protected Sub Button2_Click(ByVal
 sender As Object, _
    ByVal e As EventArgs)
    Label1.Text = "<h3>CatalogPart List</h3>"
    Dim part As CatalogPart
    For Each part In CatalogZone1.CatalogParts
      Label1.Text += part.ID + "<br />"
    Next part

  End Sub
  
  Protected Sub Button3_Click(ByVal
 sender As Object, _
    ByVal e As EventArgs)
    CatalogZone1.SelectTargetZoneText = "Add to zone"
    CatalogZone1.EmptyZoneText = "Zone is empty"
    CatalogZone1.HeaderText = "My Updated Header"
    CatalogZone1.InstructionText = "My Updated Instructions"
  End Sub
  
  Protected Sub Button4_Click(ByVal
 sender As Object, _
    ByVal e As EventArgs)
    Label1.Text = CatalogZone1.SelectedCatalogPartID
  End Sub
  
  Protected Sub Button5_Click(ByVal
 sender As Object, _
    ByVal e As EventArgs)
    CatalogZone1.PartLinkStyle.ForeColor = _
      System.Drawing.Color.Red
    CatalogZone1.SelectedPartLinkStyle.ForeColor = _
      System.Drawing.Color.Blue
  End Sub
  
</script>

<html>
  <head id="Head1" runat="server">
    <title>
      CatalogZoneBase Example
    </title>
  </head>
  <body>
    <form id="form1" runat="server">
      <asp:webpartmanager id="WebPartManager1"
 runat="server" 
        OnDisplayModeChanged="WebPartManager1_DisplayModeChanged"
 />
      <uc1:DisplayModeMenuVB ID="DisplayModeMenu1"
 runat="server" />
      <asp:webpartzone id="zone1" runat="server">
        <zonetemplate>
          <asp:BulletedList 
            ID="BulletedList1" 
            Runat="server"
            DisplayMode="HyperLink" 
            Title="Favorite Links" >
            <asp:ListItem Value="http://msdn.microsoft.com">
              MSDN
            </asp:ListItem>
            <asp:ListItem Value="http://www.asp.net">
              ASP.NET
            </asp:ListItem>
            <asp:ListItem Value="http://www.msn.com">
              MSN
            </asp:ListItem>
          </asp:BulletedList>
        </ZoneTemplate>        
      </asp:webpartzone>
      <asp:CatalogZone ID="CatalogZone1" runat="server"
        EmptyZoneText="No controls are in the zone."
        HeaderText="My Web Parts Catalog"
        InstructionText="Add Web Parts controls to the zone."
        PartLinkStyle-Font-Italic="true"
        SelectedPartLinkStyle-Font-Bold="true"
        SelectTargetZoneText="Select zone"
        AddVerb-Text="Add Control"
        CloseVerb-Description="Close and return to browse mode."
 
        SelectedCatalogPartID="Currently Selected CatalogPart
 ID.">
        <ZoneTemplate>
          <asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1"
 
            runat="server">
            <WebPartsTemplate>
              <aspSample:TextDisplayWebPart 
                runat="server"   
                id="textwebpart" 
                title = "Text Content WebPart" 
                ExportMode="All"/>  
              <asp:Calendar id="calendar1" runat="server"
 
                title="My Calendar" />        
       
            </WebPartsTemplate>
          </asp:DeclarativeCatalogPart> 
          <asp:PageCatalogPart ID="PageCatalogPart1"
 runat="server" />
          <asp:ImportCatalogPart ID="ImportCatalogPart1"
 runat="server" /> 
        </ZoneTemplate>
      </asp:CatalogZone>
      <hr />
      <asp:CatalogZone ID="CatalogZone2" runat="server"
        BorderWidth="2"
        HeaderText="My Empty CatalogZone"
        EmptyZoneText="No controls are in the zone." />
      <hr />
      <asp:Panel ID="Panel1" runat="server"
 Visible="false">
        <asp:Button ID="Button1" runat="server"
 Width="200" 
          Text="Enable or Disable Verbs" 
          OnClick="Button1_Click" />
        <br />
        <asp:Button ID="Button2" runat="server"
 Width="200" 
          Text="List CatalogParts" OnClick="Button2_Click"
 />  
        <br />
        <asp:Button ID="Button3" runat="server"
 Width="200" 
          Text="Set Zone Text Properties" OnClick="Button3_Click"
 />  
        <br />   
        <asp:Button ID="Button4" runat="server"
 Width="200" 
          Text="Show Selected CatalogPart ID" OnClick="Button4_Click"
  />  
        <br /> 
        <asp:Button ID="Button5" runat="server"
 Width="200" 
          Text="Change Part Link Styles" OnClick="Button5_Click"
  />  
        <br />     
        <asp:Label ID="Label1" runat="server"
 Text="" /></asp:Panel>
    </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">

  WebPartManager manager;

  protected void WebPartManager1_DisplayModeChanged(object
 sender,
    WebPartDisplayModeEventArgs e)
  {
    if (e.OldDisplayMode.Name != "Catalog")
      Panel1.Visible = true;
    else
      Panel1.Visible = false;
  }
  
  protected void Button1_Click(object sender,
 EventArgs e)
  {
    if (CatalogZone1.AddVerb.Enabled)
    {
      CatalogZone1.AddVerb.Enabled = false;
      CatalogZone1.CloseVerb.Enabled = false;
    }
    else
    {
      CatalogZone1.AddVerb.Enabled = true;
      CatalogZone1.CloseVerb.Enabled = true;
    }
  }

  protected void Button2_Click(object sender,
 EventArgs e)
  {
    Label1.Text = "<h3>CatalogPart List</h3>";
    foreach(CatalogPart part in CatalogZone1.CatalogParts)
    {
      Label1.Text += part.ID + "<br />";
    }
  }

  protected void Button3_Click(object sender,
 EventArgs e)
  {
    CatalogZone1.SelectTargetZoneText = "Add to zone";
    CatalogZone1.EmptyZoneText = "Zone is empty";
    CatalogZone1.HeaderText = "My Updated Header";
    CatalogZone1.InstructionText = "My Updated Instructions";
  }

  protected void Button4_Click(object sender,
 EventArgs e)
  {
    Label1.Text = CatalogZone1.SelectedCatalogPartID;
  }

  protected void Button5_Click(object sender,
 EventArgs e)
  {
    CatalogZone1.PartLinkStyle.ForeColor = System.Drawing.Color.Red;
    CatalogZone1.SelectedPartLinkStyle.ForeColor = 
      System.Drawing.Color.Blue;
  }

</script>

<html>
  <head id="Head1" runat="server">
    <title>
      CatalogZoneBase Example
    </title>
  </head>
  <body>
    <form id="form1" runat="server">
      <asp:webpartmanager id="WebPartManager1" runat="server"
 
        OnDisplayModeChanged="WebPartManager1_DisplayModeChanged" />
      <uc1:DisplayModeMenuCS ID="DisplayModeMenu1" runat="server"
 />
      <asp:webpartzone id="zone1" runat="server">
        <zonetemplate>
          <asp:BulletedList 
            ID="BulletedList1" 
            Runat="server"
            DisplayMode="HyperLink" 
            Title="Favorite Links" >
            <asp:ListItem Value="http://msdn.microsoft.com">
              MSDN
            </asp:ListItem>
            <asp:ListItem Value="http://www.asp.net">
              ASP.NET
            </asp:ListItem>
            <asp:ListItem Value="http://www.msn.com">
              MSN
            </asp:ListItem>
          </asp:BulletedList>
        </ZoneTemplate>        
      </asp:webpartzone>
      <asp:CatalogZone ID="CatalogZone1" runat="server"
        EmptyZoneText="No controls are in the zone."
        HeaderText="My Web Parts Catalog"
        InstructionText="Add Web Parts controls to the zone."
        PartLinkStyle-Font-Italic="true"
        SelectedPartLinkStyle-Font-Bold="true"
        SelectTargetZoneText="Select zone"
        AddVerb-Text="Add Control"
        CloseVerb-Description="Close and return to browse
 mode." 
        SelectedCatalogPartID="Currently Selected CatalogPart ID.">
        <ZoneTemplate>
          <asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1" 
            runat="server">
            <WebPartsTemplate>
              <aspSample:TextDisplayWebPart 
                runat="server"   
                id="textwebpart" 
                title = "Text Content WebPart" 
                ExportMode="All"/>  
              <asp:Calendar id="calendar1" runat="server"
 
                title="My Calendar" />               
            </WebPartsTemplate>
          </asp:DeclarativeCatalogPart> 
          <asp:PageCatalogPart ID="PageCatalogPart1" runat="server"
 />
          <asp:ImportCatalogPart ID="ImportCatalogPart1" runat="server"
 /> 
        </ZoneTemplate>
      </asp:CatalogZone>
      <hr />
      <asp:CatalogZone ID="CatalogZone2" runat="server"
        BorderWidth="2"
        HeaderText="My Empty CatalogZone"
        EmptyZoneText="No controls are in the zone."
 />
      <hr />
      <asp:Panel ID="Panel1" runat="server" Visible="false">
        <asp:Button ID="Button1" runat="server" Width="200"
 
          Text="Enable or Disable Verbs" 
          OnClick="Button1_Click" />
        <br />
        <asp:Button ID="Button2" runat="server" Width="200"
 
          Text="List CatalogParts" OnClick="Button2_Click" />
  
        <br />
        <asp:Button ID="Button3" runat="server" Width="200"
 
          Text="Set Zone Text Properties" OnClick="Button3_Click"
 />  
        <br />   
        <asp:Button ID="Button4" runat="server" Width="200"
 
          Text="Show Selected CatalogPart ID" OnClick="Button4_Click"
  />  
        <br /> 
        <asp:Button ID="Button5" runat="server" Width="200"
 
          Text="Change Part Link Styles" OnClick="Button5_Click"
  />  
        <br />     
        <asp:Label ID="Label1" runat="server" Text=""
 /></asp:Panel>
    </form>
  </body>
</html>

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

Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Drawing
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 _fontStyle As String
 = Nothing
    Private input As TextBox
    Private DisplayContent As Label
    Private lineBreak As Literal

    <Personalizable(), WebBrowsable()> _
    Public Property ContentText() As
 String
      Get
        Return _contentText
      End Get
      Set(ByVal value As
 String)
        _contentText = value
      End Set
    End Property

    Protected Overrides Sub
 CreateChildControls()
      Controls.Clear()
      DisplayContent = New Label()
      DisplayContent.BackColor = Color.LightBlue
      DisplayContent.Text = Me.ContentText
      Me.Controls.Add(DisplayContent)

      lineBreak = New Literal()
      lineBreak.Text = "<br />"
      Controls.Add(lineBreak)

      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)

    End Sub

    Private Sub submit_Click(ByVal
 sender As Object, _
                             ByVal e As EventArgs)
      ' Update the label string.
      If input.Text <> String.Empty Then
        _contentText = input.Text + "<br />"
        input.Text = String.Empty
        DisplayContent.Text = Me.ContentText
      End If

    End Sub

  End Class

End Namespace
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
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;
    Literal lineBreak;

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

    protected override void CreateChildControls()
    {
      Controls.Clear();
      DisplayContent = new Label();
      DisplayContent.BackColor = Color.LightBlue;
      DisplayContent.Text = this.ContentText;
      this.Controls.Add(DisplayContent);

      lineBreak = new Literal();
      lineBreak.Text = @"<br />";
      Controls.Add(lineBreak);

      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);

    }

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

  }
}

コード例正常に処理するには、Web.config ファイル追加しなければならない設定あります。これで Web パーツ記述ファイルエクスポート有効にます。このコード例Web ページと同じディレクトリに Web.config ファイルがあることを確認します<system.web> セクション内に、次のマークアップのように enableExport 属性true設定され<webParts> 要素があることを確認します

<webParts enableExport="true">

...

</webParts>

ブラウザページ読み込む場合ドロップダウン リスト ボックスの [カタログ] を選択してカタログ表示モード切り替えることができますカタログ表示されると、カタログからページ追加できる 2 つサーバー コントロール表示されます。また、CatalogZoneBase クラス メンバ宣言およびプログラムによる使用効果UI確認できます

.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.Web.UI.Control
     System.Web.UI.WebControls.WebControl
       System.Web.UI.WebControls.CompositeControl
         System.Web.UI.WebControls.WebParts.WebZone
           System.Web.UI.WebControls.WebParts.ToolZone
            System.Web.UI.WebControls.WebParts.CatalogZoneBase
               System.Web.UI.WebControls.WebParts.CatalogZone
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
CatalogZoneBase メンバ
System.Web.UI.WebControls.WebParts 名前空間
CatalogPart クラス
その他の技術情報
ASP.NET Web パーツ ページ



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

辞書ショートカット

すべての辞書の索引

「CatalogZoneBase クラス」の関連用語

CatalogZoneBase クラスのお隣キーワード
検索ランキング

   

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



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

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

©2025 GRAS Group, Inc.RSS