Share via


PersistChildrenAttribute 생성자

정의

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

오버로드

PersistChildrenAttribute(Boolean)

중첩 내용을 중첩 컨트롤로 유지할지 여부를 나타내는 부울 값을 사용하여 PersistChildrenAttribute 클래스의 새 인스턴스를 초기화합니다.

PersistChildrenAttribute(Boolean, Boolean)

두 가지 부울 값을 사용하여 PersistChildrenAttribute 클래스의 새 인스턴스를 초기화합니다. 한 부울 값은 중첩 내용을 중첩 컨트롤로 유지할지 여부를 나타내고 다른 한 부울 값은 사용자 지정 지속성 메서드를 사용할지 여부를 나타냅니다.

PersistChildrenAttribute(Boolean)

중첩 내용을 중첩 컨트롤로 유지할지 여부를 나타내는 부울 값을 사용하여 PersistChildrenAttribute 클래스의 새 인스턴스를 초기화합니다.

public:
 PersistChildrenAttribute(bool persist);
public PersistChildrenAttribute (bool persist);
new System.Web.UI.PersistChildrenAttribute : bool -> System.Web.UI.PersistChildrenAttribute
Public Sub New (persist As Boolean)

매개 변수

persist
Boolean

중첩 내용을 중첩 컨트롤로 유지하려면 true이고, 그렇지 않으면 false입니다.

예제

다음 코드 예제에서는 명명 CollectionPropertyControlPersistChildrenAttribute 사용자 지정 서버 컨트롤에 대 한 특성을 적용 하는 방법을 보여 줍니다.

이 코드 예제는에 대해 제공 된 큰 예제의 일부는 PersistChildrenAttribute 클래스입니다.

// Use the PersistChildren attribute to set the Persist
// property to false so that none of this class's
// child controls will be persisted as controls. They will
// be persisted only as child elements of this class.
// If you set the PersistChildren attribute to true, or if you
// do not include this attribute when you create a control,
// the child controls will be persisted as controls.   
[PersistChildren(false)]
[AspNetHostingPermission(SecurityAction.Demand, 
   Level=AspNetHostingPermissionLevel.Minimal)]
public sealed class CollectionPropertyControl : Control
{  
   private String header;
   private ArrayList employees = new ArrayList();
   
   public String Header
   {
      get
      {
         return header;
      }
      set
      {
         header = value;
      }
   }

   public ArrayList Employees
   {
      get 
      {
         return employees;
      }
   }
   // Override the CreateChildControls method to 
   // add child controls to the Employees property when this
   // custom control is requested from a page.
   protected override void CreateChildControls()
   {
      Label label = new Label();
      label.Text = Header;
      label.BackColor = Color.Beige;
      label.ForeColor = Color.Red;
      Controls.Add(label);
      Controls.Add(new LiteralControl("<BR> <BR>"));

      Table table = new Table();
      TableRow htr = new TableRow();

      TableHeaderCell hcell1 = new TableHeaderCell();    
      hcell1.Text = "Name";
      htr.Cells.Add(hcell1);

      TableHeaderCell hcell2 = new TableHeaderCell();
      hcell2.Text = "Title";
      htr.Cells.Add(hcell2);
      
      TableHeaderCell hcell3 = new TableHeaderCell();
      hcell3.Text = "Alias";
      htr.Cells.Add(hcell3);
      table.Rows.Add(htr);

      table.BorderWidth = 2;
      table.BackColor = Color.Beige;
      table.ForeColor = Color.Red;
      foreach (Employee employee in Employees)
      {
         TableRow tr = new TableRow();

         TableCell cell1 = new TableCell();
         cell1.Text = employee.Name;
         tr.Cells.Add(cell1);
         
         TableCell cell2 = new TableCell();
         cell2.Text = employee.Title;
         tr.Cells.Add(cell2);
         
         TableCell cell3 = new TableCell();
         cell3.Text = employee.Alias;
         tr.Cells.Add(cell3);
         
         table.Rows.Add(tr);
      }
      Controls.Add(table);
   }
}
' Use the PersistChildren attribute to set the Persist
' property to false so that none of this class's
' child controls will be persisted as controls. They will
' be persisted only as child elements of this class.
' If you set the PersistChildren attribute to true, or if you
' do not include this attribute when you create a control,
' the child controls will be persisted as controls.
<PersistChildren(False)>  _
<AspNetHostingPermission(SecurityAction.Demand, _
  Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class CollectionPropertyControl
  Inherits Control
  Private _header As String
  Private _employees As New ArrayList()
  
  
  Public Property Header() As String
     Get
        Return _header
     End Get
     Set
        _header = value
     End Set
  End Property
  
  
  
  
  Public ReadOnly Property Employees() As ArrayList
     Get
        Return _employees
     End Get
  End Property
  
  ' Override the CreateChildControls method to 
  ' add child controls to the Employees property when this
  ' custom control is requested from a page.
  Protected Overrides Sub CreateChildControls()
     Dim label As New Label()
     label.Text = Header
     label.BackColor = Color.Beige
     label.ForeColor = Color.Red
     Controls.Add(label)
     Controls.Add(New LiteralControl("<BR> <BR>"))
     
     Dim table As New Table()
     Dim htr As New TableRow()
     
     Dim hcell1 As New TableHeaderCell()
     hcell1.Text = "Name"
     htr.Cells.Add(hcell1)
     
     Dim hcell2 As New TableHeaderCell()
     hcell2.Text = "Title"
     htr.Cells.Add(hcell2)
     
     Dim hcell3 As New TableHeaderCell()
     hcell3.Text = "Alias"
     htr.Cells.Add(hcell3)
     table.Rows.Add(htr)
     
     table.BorderWidth = Unit.Pixel(2)
     table.BackColor = Color.Beige
     table.ForeColor = Color.Red
     Dim employee As Employee
     For Each employee In  Employees
        Dim tr As New TableRow()
        
        Dim cell1 As New TableCell()
        cell1.Text = employee.Name
        tr.Cells.Add(cell1)
        
        Dim cell2 As New TableCell()
        cell2.Text = employee.Title
        tr.Cells.Add(cell2)
        
        Dim cell3 As New TableCell()
        cell3.Text = employee.Alias
        tr.Cells.Add(cell3)
        
        table.Rows.Add(tr)
     Next employee
     Controls.Add(table)
  End Sub
End Class

추가 정보

적용 대상

PersistChildrenAttribute(Boolean, Boolean)

두 가지 부울 값을 사용하여 PersistChildrenAttribute 클래스의 새 인스턴스를 초기화합니다. 한 부울 값은 중첩 내용을 중첩 컨트롤로 유지할지 여부를 나타내고 다른 한 부울 값은 사용자 지정 지속성 메서드를 사용할지 여부를 나타냅니다.

public:
 PersistChildrenAttribute(bool persist, bool usesCustomPersistence);
public PersistChildrenAttribute (bool persist, bool usesCustomPersistence);
new System.Web.UI.PersistChildrenAttribute : bool * bool -> System.Web.UI.PersistChildrenAttribute
Public Sub New (persist As Boolean, usesCustomPersistence As Boolean)

매개 변수

persist
Boolean

중첩 내용을 중첩 컨트롤로 유지하려면 true이고, 그렇지 않으면 false입니다.

usesCustomPersistence
Boolean

사용자 지정 지속성을 사용하려면 true이고, 그렇지 않으면 false입니다.

적용 대상