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

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DeclarativeCatalogPart クラスの意味・解説 

DeclarativeCatalogPart クラス

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

開発者WebPart または他のサーバー コントロールカタログ宣言によってページ永続形式Web ページ追加できるようにします。このクラス継承できません。

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

Public NotInheritable Class
 DeclarativeCatalogPart
    Inherits CatalogPart
Dim instance As DeclarativeCatalogPart
public sealed class DeclarativeCatalogPart
 : CatalogPart
public ref class DeclarativeCatalogPart sealed
 : public CatalogPart
public final class DeclarativeCatalogPart extends
 CatalogPart
public final class DeclarativeCatalogPart extends
 CatalogPart
解説解説

Web パーツ コントロール セット (詳細については ToolZone クラス概要参照) 内にツール指向ゾーンあるように、ツール指向Part コントロールがあり、これらのコントロールそれぞれ特定のタイプツール ゾーン配置する必要がありますWeb パーツ コントロール セットツール指向パーツ コントロールには、2 つ際立った特性あります

DeclarativeCatalogPart は、Web パーツ コントロール セットによって提供される CatalogZone ゾーンのような CatalogZoneBase 型のゾーン配置する必要があるパーツ コントロールです。DeclarativeCatalogPart コントロールは、Web ページカタログ表示モード場合のみ表示されます。

DeclarativeCatalogPart コントロール使用すると、開発者サーバー コントロールセット宣言によって Web ページカタログ追加できますカタログは、Web パーツ コントロール セット内では、ページカタログ表示モードになったときに表示される WebPart または他のサーバー コントロール単純なリストです。ユーザーは、リストからコントロール選択して、それを Web ページ追加できます。これで、事実上ユーザーページコントロールセットおよび機能変更できます

メモメモ

ユーザーは、カタログ内の同一コントロール複数インスタンスWeb ページ追加できます

DeclarativeCatalogPart コントロール使用してサーバー コントロールカタログ作成する利点は、コーディングを必要としないことです。ページ開発者は、コントロール宣言 (またはページ永続) 形式、つまりコントロールの名前で完全に操作できます

DeclarativeCatalogPart コントロールには、開発者サイト全体使用できるコントロールカタログ設定できるようにする便利なプロパティあります開発者は、DeclarativeCatalogPart コントロール内で個別サーバー コントロール宣言するではなく、WebPartsListUserControlPath プロパティ値を、カタログ配置するサーバー コントロールリストを含むユーザー コントロールパス設定できます実行時に、ユーザー コントロール参照されるサーバー コントロールカタログ読み込まれます。この方法では、複数ページまたはサイトが同じユーザー コントロール参照してカタログ作成できますユーザー コントロールサーバー コントロール リスト更新されると、そのユーザー コントロールに基づくすべてカタログ更新されます。

DeclarativeCatalogPart クラスには、継承プロパティオーバーライドする多数パブリック プロパティあります。これらのプロパティのほとんどは、実際にコントロールレンダリングには使用されません。これらがオーバーライドされるのは、特別なコード属性Microsoft Visual Studio 2005 のようなデザイン ツールで非表示にする設定ができるようにするためだけです。これらの非表示プロパティレンダリングには何の効果もないので、使用しないください。これらが IntelliSense および Visual Studioプロパティ ペイン表示されないことで、開発者誤って使用するのを防ぐことができます。これらの非表示プロパティについては、すべてそれぞれのヘルプ トピックその旨記載されています。

DeclarativeCatalogPart クラスにはメソッドいくつかあります。GetAvailableWebPartDescriptions メソッドは、カタログ内のWebPart コントロール対する WebPartDescription オブジェクト取得しますカタログでは、DeclarativeCatalogPart コントロール使用することで、各サーバー コントロールについての情報をそのコントロールインスタンス作成しなくても表示できます。他に、GetWebPart メソッドあります。このメソッドは、メソッド渡される説明基づいて特定の WebPart コントロールインスタンス取得します

使用例使用例

Web ページ上の DeclarativeCatalogPart コントロール宣言によって使用する方法次のコード例示します。例は 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 番目の部分Web ページです。ページ先頭には 2 つRegister ディレクティブあります1 つユーザー コントロール用で、もう 1 つは、2 つカスタム WebPart コントロール格納しているコンパイル済みコンポーネント用です。このトピックの「解説セクション記述されているように、ページには、適切な宣言要素階層内に入れ子になった DeclarativeCatalogPart コントロールへの宣言参照あります<asp:declarativecatalogpart> 要素は、<webpartstemplate> 要素格納します同様に後者は、標準 ASP.NET Calendar コントロール参照、および 2 つカスタム WebPart コントロール格納します。これらは、ユーザーカタログから選択できるコントロールです。ページには、ページ宣言されている PropertyGridEditorPart コントロール使用する編集機能あります。このコントロール使用してユーザーは、ページ追加された後のカスタム WebPart コントロール特定のプロパティを、ページ編集モード切り替えた後に編集できます

<%@ page language="VB" %>
<%@ register TagPrefix="uc1" 
  TagName="DisplayModeMenuVB" 
  Src="DisplayModeMenuVB.ascx" %>
<%@ register tagprefix="aspSample" 
  Namespace="Samples.AspNet.VB.Controls"
 
  Assembly="UserInfoWebPartVB"
 %>

<html>
  <head runat="server">
    <title>
      DeclarativeCatalogPart Control
    </title>
  </head>
  <body>
    <form id="form1" runat="server">
      <asp:webpartmanager id="WebPartManager1"
 runat="server"  />
      <uc1:DisplayModeMenuVB ID="DisplayModeMenu1"
 runat="server" />
      <asp:webpartzone id="zone1" runat="server"
 >
        <PartTitleStyle BorderWidth=1 
          Font-Names="Verdana, Arial"
          Font-Size="110%"
          BackColor="LightBlue" />
        <zonetemplate>
          <asp:BulletedList ID="BulletedList1"
 
            Runat="server"
            DisplayMode="HyperLink"
            Title="Favorites">
            <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">
        <ZoneTemplate>
          <asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1"
  
            runat="server" 
            Title="Web Parts Catalog"
            ChromeType="TitleOnly" 
            Description="Contains a user control with Web
 Parts and 
              an ASP.NET Calendar control.">
            <WebPartsTemplate>
              <asp:Calendar ID="Calendar1" runat="server"
 
                Title="My Calendar" 
                Description="ASP.NET Calendar control used as
 a personal calendar." />
              <aspSample:UserInfoWebPart 
                runat="server"   
                id="userinfo1" 
                title = "User Information WebPart"
                Description ="Contains custom, editable user information 
                  for display on a page."
 />
              <aspSample:TextDisplayWebPart 
                runat="server"   
                id="TextDisplayWebPart1" 
                title = "Text Display WebPart" 
                Description="Contains a label that users can dynamically
 update." />
            </WebPartsTemplate>              
          </asp:DeclarativeCatalogPart>
        </ZoneTemplate>
      </asp:CatalogZone>
      <asp:EditorZone ID="EditorZone1" runat="server">
      <ZoneTemplate>
        <asp:PropertyGridEditorPart ID="PropertyGridEditorPart1"
 runat="server" />
      </ZoneTemplate>
      </asp:EditorZone> 
    </form>
  </body>
</html>
<%@ page language="c#" %>
<%@ register TagPrefix="uc1" 
  TagName="DisplayModeMenuCS" 
  Src="DisplayModeMenuCS.ascx" %>
<%@ register tagprefix="aspSample" 
  Namespace="Samples.AspNet.CS.Controls" 
  Assembly="UserInfoWebPartCS" %>

<html>
  <head id="Head1" runat="server">
    <title>
      DeclarativeCatalogPart Control
    </title>
  </head>
  <body>
    <form id="form1" runat="server">
      <asp:webpartmanager id="WebPartManager1" runat="server"
  />
      <uc1:DisplayModeMenuCS ID="DisplayModeMenu1" runat="server"
 />
      <asp:webpartzone id="zone1" runat="server" >
        <PartTitleStyle BorderWidth=1 
          Font-Names="Verdana, Arial"
          Font-Size="110%"
          BackColor="LightBlue" />
        <zonetemplate>
          <asp:BulletedList ID="BulletedList1" 
            Runat="server"
            DisplayMode="HyperLink"
            Title="Favorites">
            <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">
        <ZoneTemplate>
          <asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1" 
 
            runat="server" 
            Title="Web Parts Catalog"
            ChromeType="TitleOnly" 
            Description="Contains a user control with Web Parts and 
              an ASP.NET Calendar control.">
            <WebPartsTemplate>
              <asp:Calendar ID="Calendar1" runat="server"
 
                Title="My Calendar" 
                Description="ASP.NET Calendar control used as a personal calendar."
 />
              <aspSample:UserInfoWebPart 
                runat="server"   
                id="userinfo1" 
                title = "User Information WebPart"
                Description ="Contains custom, editable user information 
                  for display on a page." />
              <aspSample:TextDisplayWebPart 
                runat="server"   
                id="TextDisplayWebPart1" 
                title = "Text Display WebPart" 
                Description="Contains a label that users can dynamically update."
 />
            </WebPartsTemplate>              
          </asp:DeclarativeCatalogPart>
        </ZoneTemplate>
      </asp:CatalogZone>
      <asp:EditorZone ID="EditorZone1" runat="server">
      <ZoneTemplate>
        <asp:PropertyGridEditorPart ID="PropertyGridEditorPart1" runat="server"
 />
      </ZoneTemplate>
      </asp:EditorZone> 
    </form>
  </body>
</html>

コード例3 番目の部分は、2 つWebPart コントロールソース コードです。これらのコントロールいくつかのプロパティは、WebBrowsable 属性マークされています。これによって、PropertyGridEditorPart コントロールは、編集モードのときにユーザーがそれらのプロパティ編集するためのユーザー インターフェイス (UI) を動的に生成できますプロパティは、WebDisplayName 属性でもマークされています。これによって、編集中の UI で各コントロールの横に表示されるラベルテキスト指定します

コード例実行するためには、このソース コードコンパイルする必要があります。それを明示的にコンパイルし、コンパイル済みアセンブリ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 UserInfoWebPart
    Inherits WebPart
    Private server As HttpServerUtility = HttpContext.Current.Server
    Private _userNickName As String
 = "Add a nickname."
    Private _userPetName As String
 = "Add a pet's name."
    Private _userSpecialDate As DateTime =
 DateTime.Now
    Private _userIsCurrent As [Boolean] = True
    Private _userJobType As JobTypeName = JobTypeName.Unselected

    Public Enum JobTypeName
      Unselected = 0
      Support = 1
      Service = 2
      Professional = 3
      Technical = 4
      Manager = 5
      Executive = 6
    End Enum

    Private NickNameLabel As Label
    Private PetNameLabel As Label
    Private SpecialDateLabel As Label
    Private IsCurrentCheckBox As CheckBox
    Private JobTypeLabel As Label

    ' Add the Personalizable and WebBrowsable attributes to the  
    ' public properties, so that users can save property values  
    ' and edit them with a PropertyGridEditorPart control.

    <Personalizable(), WebBrowsable(), WebDisplayName("Nickname")>
 _
    Public Property NickName() As
 String
      Get
        Dim o As Object
 = ViewState("NickName")
        If Not (o Is Nothing)
 Then
          Return CStr(o)
        Else
          Return _userNickName
        End If
      End Get
      Set(ByVal value As
 String)
        _userNickName = server.HtmlEncode(value)
      End Set
    End Property

    <Personalizable(), WebBrowsable(), WebDisplayName("Pet
 Name")> _
    Public Property PetName() As
 String
      Get
        Dim o As Object
 = ViewState("PetName")
        If Not (o Is Nothing)
 Then
          Return CStr(o)
        Else
          Return _userPetName
        End If
      End Get
      Set(ByVal value As
 String)
        _userPetName = server.HtmlEncode(value)
      End Set
    End Property

    <Personalizable(), WebBrowsable(), WebDisplayName("Special
 Day")> _
    Public Property SpecialDay() As
 DateTime
      Get
        Dim o As Object
 = ViewState("SpecialDay")
        If Not (o Is Nothing)
 Then
          Return CType(o, DateTime)
        Else
          Return _userSpecialDate
        End If
      End Get

      Set(ByVal value As
 DateTime)
        _userSpecialDate = value
      End Set
    End Property

    <Personalizable(), WebBrowsable(), WebDisplayName("Job
 Type")> _
    Public Property UserJobType() As
 JobTypeName
      Get
        Dim o As Object
 = ViewState("UserJobType")
        If Not (o Is Nothing)
 Then
          Return CType(o, JobTypeName)
        Else
          Return _userJobType
        End If
      End Get
      Set(ByVal value As
 JobTypeName)
        _userJobType = CType(value, JobTypeName)
      End Set
    End Property

    <Personalizable(), WebBrowsable(), WebDisplayName("Is Current")>
 _
    Public Property IsCurrent() As
 [Boolean]
      Get
        Dim o As Object
 = ViewState("IsCurrent")
        If Not (o Is Nothing)
 Then
          Return CType(o, [Boolean])
        Else
          Return _userIsCurrent
        End If
      End Get
      Set(ByVal value As
 [Boolean])
        _userIsCurrent = value
      End Set
    End Property

    Protected Overrides Sub
 CreateChildControls()
      Controls.Clear()

      NickNameLabel = New Label()
      NickNameLabel.Text = Me.NickName
      SetControlAttributes(NickNameLabel)

      PetNameLabel = New Label()
      PetNameLabel.Text = Me.PetName
      SetControlAttributes(PetNameLabel)

      SpecialDateLabel = New Label()
      SpecialDateLabel.Text = Me.SpecialDay.ToShortDateString()
      SetControlAttributes(SpecialDateLabel)

      IsCurrentCheckBox = New CheckBox()
      IsCurrentCheckBox.Checked = Me.IsCurrent
      SetControlAttributes(IsCurrentCheckBox)

      JobTypeLabel = New Label()
      JobTypeLabel.Text = Me.UserJobType.ToString()
      SetControlAttributes(JobTypeLabel)

      ChildControlsCreated = True

    End Sub

    Private Sub SetControlAttributes(ByVal
 ctl As WebControl)
      ctl.BackColor = Color.White
      ctl.BorderWidth = 1
      ctl.Width = 200
      Me.Controls.Add(ctl)
    End Sub

    Protected Overrides Sub
 RenderContents(ByVal writer As HtmlTextWriter)
      writer.Write("Nickname:")
      writer.WriteBreak()
      NickNameLabel.RenderControl(writer)
      writer.WriteBreak()
      writer.Write("Pet Name:")
      writer.WriteBreak()
      PetNameLabel.RenderControl(writer)
      writer.WriteBreak()
      writer.Write("Special Date:")
      writer.WriteBreak()
      SpecialDateLabel.RenderControl(writer)
      writer.WriteBreak()
      writer.Write("Job Type:")
      writer.WriteBreak()
      JobTypeLabel.RenderControl(writer)
      writer.WriteBreak()
      writer.Write("Current:")
      writer.WriteBreak()
      IsCurrentCheckBox.RenderControl(writer)

    End Sub

  End Class


  <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 UserInfoWebPart : WebPart
  {
    HttpServerUtility server = HttpContext.Current.Server;
    private String _userNickName = "Add a nickname.";
    private String _userPetName = "Add a pet's name.";
    private DateTime _userSpecialDate = DateTime.Now;
    private Boolean _userIsCurrent = true;
    private JobTypeName _userJobType = JobTypeName.Unselected;
    public enum JobTypeName
    {
      Unselected = 0,
      Support = 1,
      Service = 2,
      Professional = 3, 
      Technical = 4,
      Manager = 5,
      Executive = 6
    }
    Label NickNameLabel;
    Label PetNameLabel;
    Label SpecialDateLabel;
    CheckBox IsCurrentCheckBox;
    Label JobTypeLabel;

    // Add the Personalizable and WebBrowsable attributes to the  
    // public properties, so that users can save property values  
    // and edit them with a PropertyGridEditorPart control.
    [Personalizable(), WebBrowsable, WebDisplayName("Nickname")]
    public String NickName
    {
      get 
      { 
        object o = ViewState["NickName"];
        if (o != null)
          return (string)o;
        else
          return _userNickName;        
      } 

      set { _userNickName = server.HtmlEncode(value); }
    }

    [Personalizable(), WebBrowsable, WebDisplayName("Pet Name")]
    public String PetName
    {
      get 
      { 
        object o = ViewState["PetName"];
        if (o != null)
          return (string)o;
        else
          return _userPetName;        
      }

      set { _userPetName = server.HtmlEncode(value); }
    }

    [Personalizable(), WebBrowsable(), WebDisplayName("Special Day")]
    public DateTime SpecialDay
    {
      get
      {
        object o = ViewState["SpecialDay"];
        if (o != null)
          return (DateTime)o;
        else
          return _userSpecialDate;
        
      }

      set { _userSpecialDate = value; }
    }

    [Personalizable(), WebBrowsable(), WebDisplayName("Job Type")]
    public JobTypeName UserJobType
    {
      get
      {
        object o = ViewState["UserJobType"];
        if (o != null)
          return (JobTypeName)o;
        else
          return _userJobType;
      }

      set { _userJobType = (JobTypeName)value; }
    }

    [Personalizable(), WebBrowsable(), WebDisplayName("Is Current")]
    public Boolean IsCurrent
    {
      get
      {
        object o = ViewState["IsCurrent"];
        if (o != null)
          return (Boolean)o;
        else
          return _userIsCurrent;
      }

      set { _userIsCurrent = value; }
    }


    protected override void CreateChildControls()
    {
      Controls.Clear();

      NickNameLabel = new Label();
      NickNameLabel.Text = this.NickName;
      SetControlAttributes(NickNameLabel);

      PetNameLabel = new Label();
      PetNameLabel.Text = this.PetName;
      SetControlAttributes(PetNameLabel);

      SpecialDateLabel = new Label();
      SpecialDateLabel.Text = this.SpecialDay.ToShortDateString();
      SetControlAttributes(SpecialDateLabel);

      IsCurrentCheckBox = new CheckBox();
      IsCurrentCheckBox.Checked = this.IsCurrent;
      SetControlAttributes(IsCurrentCheckBox);

      JobTypeLabel = new Label();
      JobTypeLabel.Text = this.UserJobType.ToString();
      SetControlAttributes(JobTypeLabel);

      ChildControlsCreated = true;

    }

    private void SetControlAttributes(WebControl
 ctl)
    {
      ctl.BackColor = Color.White;
      ctl.BorderWidth = 1;
      ctl.Width = 200;
      this.Controls.Add(ctl);
    }

    protected override void RenderContents(HtmlTextWriter
 writer)
    {
      writer.Write("Nickname:");
      writer.WriteBreak();
      NickNameLabel.RenderControl(writer);
      writer.WriteBreak();
      writer.Write("Pet Name:");
      writer.WriteBreak();
      PetNameLabel.RenderControl(writer);
      writer.WriteBreak();
      writer.Write("Special Date:");
      writer.WriteBreak();
      SpecialDateLabel.RenderControl(writer);
      writer.WriteBreak();
      writer.Write("Job Type:");
      writer.WriteBreak();
      JobTypeLabel.RenderControl(writer);
      writer.WriteBreak();
      writer.Write("Current:");
      writer.WriteBreak();
      IsCurrentCheckBox.RenderControl(writer);
    }
  }


  [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;
      }
    }

  }

}

ブラウザページ読み込む場合は、[Display Mode] ドロップダウン リスト コントロールの [Catalog Mode] を選択してカタログ モード切り替えますカタログ モードでは、ページへの追加可能なコントロール表示できます3 つのコントロールをすべて追加し、[Display Mode] ドロップダウン リスト使用してページブラウズ モード戻します3 つのコントロールページ表示されます。[Display Mode] ドロップダウン リスト使用してページ編集モード切り替えた場合、[User Information WebPart] コントロールタイトル バー動詞メニュー (下向き矢印) をクリックし、[編集] をクリックしてコントロール編集できます編集中の UI表示すると、PropertyGridEditorPart コントロール確認できますコントロールは、WebBrowsable 属性マークされていた UserInfoWebPart クラスの各プロパティについてレンダリングされます編集中の UI変更行い、[適用] ボタンクリックした場合、[Display Mode] ドロップダウン リスト使用してページブラウズ モード戻し編集中の変更をすべて反映した結果表示できます

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



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

辞書ショートカット

すべての辞書の索引

「DeclarativeCatalogPart クラス」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS