Share via


CatalogZone 생성자

정의

CatalogZone 클래스의 새 인스턴스를 초기화합니다.

public:
 CatalogZone();
public CatalogZone ();
Public Sub New ()

예제

다음 코드 예제에서는 사용자 지정 CatalogZone 컨트롤에서 생성자의 프로그래밍 방식으로 사용 CatalogZone 하는 방법을 보여 줍니다. 생성자는 컨트롤의 일부 기본 속성 값을 초기화하는 데 사용됩니다. 다음 코드는 맨 위에 선언된 생성자를 사용하여 사용자 지정 CatalogZone 클래스를 보여 있습니다. 예제를 설정하고 실행하는 데 필요한 전체 코드 및 지침은 클래스 개요의 예제 섹션을 CatalogZone 참조하세요.

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
{
  // Create a customized CatalogZone control by setting 
  // some properties in the constructor.
  [AspNetHostingPermission(SecurityAction.Demand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  [AspNetHostingPermission(SecurityAction.InheritanceDemand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  public class MyCatalogZone : CatalogZone
  {
    public MyCatalogZone()
    {
      this.HeaderText = "My Company Catalog";
      this.HeaderCloseVerb.Text = "Close Catalog";
      this.CloseVerb.Text = "Close Catalog";
    }
  }

  // Create a custom WebPart control to add to a WebPartZone.
  [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 (!string.IsNullOrEmpty(input.Text))
      {
        _contentText = input.Text + @"<br />";
        input.Text = String.Empty;
        DisplayContent.Text = this.ContentText;
      }
    }
  }
}
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

  ' Create a custom CatalogZone control by setting some 
  ' properties in the constructor.
  <AspNetHostingPermission(SecurityAction.Demand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
  <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
    Level:=AspNetHostingPermissionLevel.Minimal)> _
  Public Class MyCatalogZone
    Inherits CatalogZone

    Public Sub New()
      Me.HeaderText = "My Company Catalog"
      Me.HeaderCloseVerb.Text = "Close Catalog"
      Me.CloseVerb.Text = "Close Catalog"
    End Sub

  End Class


  ' Create a custom WebPart to add to a WebPartZone.
  <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

설명

컨트롤은 CatalogZone 영역 템플릿을 구현하기 때문에 일반적으로 선언적으로 사용되며 생성자를 사용하여 CatalogZone 클래스의 새 인스턴스를 만들 필요가 거의 없습니다. 그러나 클래스에서 CatalogZone 상속하여 사용자 지정 영역을 만드는 경우 생성자를 사용하여 일부 속성 값을 초기화하고 모양을 사용자 지정할 수 있습니다.

적용 대상

추가 정보