ParseChildrenAttribute ParseChildrenAttribute ParseChildrenAttribute ParseChildrenAttribute Class

Definition

Definiert ein Metadatenattribut, das bei der Entwicklung von ASP.NET-Serversteuerelementen verwendet werden kann.Defines a metadata attribute that you can use when developing ASP.NET server controls. Mit der ParseChildrenAttribute-Klasse können Sie angeben, wie der Seitenparser mit Inhalten verfahren soll, die in einem auf einer Seite deklarierten Serversteuerelementtag geschachtelt sind.Use the ParseChildrenAttribute class to indicate how the page parser should treat content nested inside a server control tag declared on a page. Diese Klasse kann nicht vererbt werden.This class cannot be inherited.

public ref class ParseChildrenAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class)]
public sealed class ParseChildrenAttribute : Attribute
type ParseChildrenAttribute = class
    inherit Attribute
Public NotInheritable Class ParseChildrenAttribute
Inherits Attribute
Vererbung
ParseChildrenAttributeParseChildrenAttributeParseChildrenAttributeParseChildrenAttribute
Attribute

Beispiele

Das Codebeispiel in diesem Abschnitt enthält zwei Teile.The code example in this section contains two parts. Im ersten Codebeispiel wird veranschaulicht, wie Eigenschaften für die ParseChildrenAttribute -Klasse festgelegt werden.The first code example demonstrates how to set properties for the ParseChildrenAttribute class. Im zweiten Codebeispiel wird veranschaulicht, wie Klassen auf einer ASP.NET-Seite verwendet werden.The second code example demonstrates how to use classes in an ASP.NET page.

Im folgenden Codebeispiel wird veranschaulicht, wie das ParseChildrenAttribute -Objekt eines benutzerdefinierten Server Steuer CollectionPropertyControlElements namensfest gelegt wird.The following code example demonstrates how to set the ParseChildrenAttribute object of a custom server control named CollectionPropertyControl. Der ParseChildrenAttribute true DefaultProperty legt die- Employee Eigenschaft auf und die-Eigenschaft auf die-Klasse fest. ChildrenAsPropertiesThe ParseChildrenAttribute sets the ChildrenAsProperties property to true and the DefaultProperty property to the Employee class.

using System;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Permissions;

namespace Samples.AspNet.CS.Controls
{
   // The child element class.
   [AspNetHostingPermission(SecurityAction.Demand, 
      Level=AspNetHostingPermissionLevel.Minimal)]
   public sealed class Employee
   {
      private String name;
      private String title;
      private String alias;

      public Employee():this ("","",""){}
      
      public Employee (String name, String title, String alias)
      {
         this.name = name;
         this.title = title;
         this.alias = alias;
      }
      public String Name
      {
         get
         {
            return name;
         }
         set
         {
            name = value;
         }
      }
      
      public String Title
      {
         get
         {
            return title;
         }
         set
         {
            title = value;
         }
      }
      
      public String Alias
      {
         get
         {
            return alias;
         }
         set
         {
            alias = value;
         }
      }
   }
   // Use the ParseChildren attribute to set the ChildrenAsProperties
   // and DefaultProperty properties. Using this constructor, the
   // control parses all child controls as properties and must define
   // a public property named Employees, which it declares as
   // an ArrayList. Nested (child) elements must correspond to
   // child elements of the Employees property or to other
   // properties of the control.  
   [ParseChildren(true, "Employees")]
   [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 = System.Drawing.Color.Beige;
         label.ForeColor = System.Drawing.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 = System.Drawing.Color.Beige;
         table.ForeColor = System.Drawing.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);
         
      }
   }
}
Imports System.Collections
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Security.Permissions

Namespace Samples.AspNet.VB.Controls


    ' The child element class.

    <AspNetHostingPermission(SecurityAction.Demand, _
       Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public NotInheritable Class Employee
        Private _name As String
        Private _title As String
        Private _alias As String


        Public Sub New()
            Me.New("", "", "")
        End Sub 'New


        Public Sub New(ByVal name As String, ByVal title As String, ByVal employeeAlias As String)
            Me._name = name
            Me._title = title
            Me._alias = employeeAlias
        End Sub 'New

        Public Property Name() As String
            Get
                Return _name
            End Get
            Set(ByVal value As String)
                _name = Value
            End Set
        End Property


        Public Property Title() As String
            Get
                Return _title
            End Get
            Set(ByVal value As String)
                _title = Value
            End Set
        End Property


        Public Property [Alias]() As String
            Get
                Return _alias
            End Get
            Set(ByVal value As String)
                _alias = Value
            End Set
        End Property
    End Class 'Employee
    ' Use the ParseChildren attribute to set the ChildrenAsProperties
    ' and DefaultProperty properties. Using this constructor, the
    ' control parses all child controls as properties and must define
    ' a public property named Employees, which it declares as
    ' an ArrayList. Nested (child) elements must correspond to
    ' child elements of the Employees property or to other
    ' properties of the control.   
    <ParseChildren(True, "Employees")> _
    <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(ByVal value As String)
                _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 = System.Drawing.Color.Beige
            label.ForeColor = System.Drawing.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 = System.Drawing.Color.Beige
            table.ForeColor = System.Drawing.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 'CreateChildControls 
    End Class 
End Namespace

Im folgenden Codebeispiel wird veranschaulicht, wie die CollectionPropertyControl - Employee Klasse und die-Klasse auf einer ASP.NET-Seite verwendet werden.The following code example demonstrates how to use the CollectionPropertyControl and Employee classes in an ASP.NET page. Instanzen der Employee -Klasse werden deklarativ hinzugefügt.Instances of the Employee class are added declaratively.

<%@ Page Language="C#" Debug="true" %>
<%@ Register TagPrefix="AspSample" Assembly="Samples.AspNet.CS.Controls" Namespace="Samples.AspNet.CS.Controls" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

  protected void Page_Load(object sender, EventArgs e)
  {
    
    // Verify attribute values.
    ParseChildrenAttribute p = 
      (ParseChildrenAttribute)Attribute.GetCustomAttribute(typeof(CollectionPropertyControl),
      typeof(ParseChildrenAttribute));

    StringBuilder sb = new StringBuilder();
    sb.Append("The DefaultProperty property is " + p.DefaultProperty.ToString() + "<br />");
    sb.Append("The ChildrenAsProperties property is " + p.ChildrenAsProperties.ToString() + "<br />");
    sb.Append("The IsDefaultAttribute method returns " + p.IsDefaultAttribute().ToString());
    Message.Text = sb.ToString();

  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>ParseChildrenAttribute Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:Label ID="Message"
                 runat="server"/>
      <AspSample:CollectionPropertyControl id="CollectionPropertyControl1" 
                                           runat="server">
        <AspSample:Employee Name="Employee 1" 
                            Title="Title 1" 
                            Alias="Alias 1" />
        <AspSample:Employee Name="Employee 2" 
                            Title="Title 2" 
                            Alias="Alias 2" />
      </AspSample:CollectionPropertyControl>    
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ Register TagPrefix="AspSample" Assembly="Samples.AspNet.VB.Controls" Namespace="Samples.AspNet.VB.Controls" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
  
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    
    ' Verify attribute values.
    Dim p As ParseChildrenAttribute = _
    Attribute.GetCustomAttribute(GetType(CollectionPropertyControl), _
    GetType(ParseChildrenAttribute))

    Dim sb As New StringBuilder()
    sb.Append("The DefaultProperty property is " & p.DefaultProperty.ToString() & "<br />")
    sb.Append("The ChildrenAsProperties property is " & p.ChildrenAsProperties.ToString() & "<br />")
    sb.Append("The IsDefaultAttribute method returns " & p.IsDefaultAttribute().ToString())
    Message.Text = sb.ToString()

  End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>PersistChildrenAttribute</title>
</head>
<body>
    <form id="Form1" runat="server">
    <div>
      <asp:Label ID="Message"
                 runat="server"/>
      <AspSample:CollectionPropertyControl id="CollectionPropertyControl1" 
                                           runat="server">
        <AspSample:Employee Name="Employee 1" 
                            Title="Title 1" 
                            Alias="Alias 1" />
        <AspSample:Employee Name="Employee 2" 
                            Title="Title 2" 
                            Alias="Alias 2" />
      </AspSample:CollectionPropertyControl>
    </div>
    </form>
</body>
</html>

Hinweise

Mit ParseChildrenAttribute der-Klasse können Sie die Logik für ein benutzerdefiniertes Server Steuerelement angeben, indem Sie das ParseChildrenAttribute -Server Steuerelement mit dem Metadata-Attribut markieren.The ParseChildrenAttribute class allows you to specify parsing logic for a custom server control by marking the server control with the ParseChildrenAttribute metadata attribute.

Wenn Sie das-Server Steuerelement mit ParseChildren(true) dem Metadata-Attribut markieren, weist den Parser an, die Elemente, die in den Tags des Server Steuer Elements enthalten sind, als Eigenschaften zu interpretieren.Marking your server control with the metadata attribute ParseChildren(true) instructs the parser to interpret the elements that are contained within the server control's tags as properties. In diesem Szenario ist ChildrenAsProperties truedie-Eigenschaft.In this scenario, the ChildrenAsProperties property is true.

Wenn Sie das Server Steuerelement mit dem ParseChildren(true,"<Default Property>") Metadata- DefaultProperty Attribut markieren, wird die-Eigenschaft auf den Namen der Eigenschaft festgelegt, die an das Attribut übermittelt wird.Marking your server control with the metadata attribute ParseChildren(true,"<Default Property>") sets the DefaultProperty property to the name of the property that is passed into the attribute.

Wenn das Server Steuerelement mit dem Metadatenattribut ParseChildren(false)markiert wird, weist der Standardwert den Parser an, die Elemente, die in den Tags des Server Steuer Elements enthalten sind, als Inhalt zu interpretieren, der mit einem zugeordneten ControlBuilder analysiert wird, das ist. als Steuerelemente.Marking your server control with the metadata attribute ParseChildren(false), the default value, instructs the parser to interpret the elements that are contained within the server control's tags as content that will be parsed with an associated ControlBuilder that is, as controls. In diesem Szenario ist ChildrenAsProperties falsedie-Eigenschaft.In this scenario, the ChildrenAsProperties property is false.

Weitere Informationen zum Verwenden von Attributen finden Sie unter Attribute.For information about using attributes, see Attributes.

Konstruktoren

ParseChildrenAttribute() ParseChildrenAttribute() ParseChildrenAttribute() ParseChildrenAttribute()

Initialisiert eine neue Instanz der ParseChildrenAttribute-Klasse.Initializes a new instance of the ParseChildrenAttribute class.

ParseChildrenAttribute(Boolean) ParseChildrenAttribute(Boolean) ParseChildrenAttribute(Boolean) ParseChildrenAttribute(Boolean)

Initialisiert eine neue Instanz der ParseChildrenAttribute-Klasse, wobei mithilfe der ChildrenAsProperties-Eigenschaft bestimmt wird, ob die in einem Serversteuerelement enthaltenen Elemente als Eigenschaften des Serversteuerelements analysiert werden.Initializes a new instance of the ParseChildrenAttribute class using the ChildrenAsProperties property to determine if the elements that are contained within a server control are parsed as properties of the server control.

ParseChildrenAttribute(Boolean, String) ParseChildrenAttribute(Boolean, String) ParseChildrenAttribute(Boolean, String) ParseChildrenAttribute(Boolean, String)

Initialisiert eine neue Instanz der ParseChildrenAttribute-Klasse mithilfe des childrenAsProperties-Parameters und des defaultProperty-Parameters.Initializes a new instance of the ParseChildrenAttribute class using the childrenAsProperties and defaultProperty parameters.

ParseChildrenAttribute(Type) ParseChildrenAttribute(Type) ParseChildrenAttribute(Type) ParseChildrenAttribute(Type)

Initialisiert eine neue Instanz der ParseChildrenAttribute-Klasse, wobei mithilfe der ChildControlType-Eigenschaft bestimmt wird, welche der in einem Serversteuerelement enthaltenen Elemente als Steuerelemente analysiert werden.Initializes a new instance of the ParseChildrenAttribute class using the ChildControlType property to determine which elements that are contained within a server control are parsed as controls.

Felder

Default Default Default Default

Definiert den Standardwert für die ParseChildrenAttribute-Klasse.Defines the default value for the ParseChildrenAttribute class. Dieses Feld ist schreibgeschützt.This field is read-only.

ParseAsChildren ParseAsChildren ParseAsChildren ParseAsChildren

Gibt an, dass die in einem Serversteuerelement enthaltenen geschachtelten Inhalte als Steuerelemente analysiert werden.Indicates that the nested content that is contained within the server control is parsed as controls.

ParseAsProperties ParseAsProperties ParseAsProperties ParseAsProperties

Gibt an, dass die in einem Serversteuerelement enthaltenen geschachtelten Inhalte als Eigenschaften des Steuerelements analysiert werden.Indicates that the nested content that is contained within a server control is parsed as properties of the control.

Eigenschaften

ChildControlType ChildControlType ChildControlType ChildControlType

Ruft einen Wert ab, der den zulässigen Typ eines Steuerelements angibt.Gets a value indicating the allowed type of a control.

ChildrenAsProperties ChildrenAsProperties ChildrenAsProperties ChildrenAsProperties

Ruft einen Wert ab, der angibt, ob die in einem Serversteuerelement enthaltenen Elemente als Eigenschaften analysiert werden sollen, oder legt diesen Wert fest.Gets or sets a value indicating whether to parse the elements that are contained within a server control as properties.

DefaultProperty DefaultProperty DefaultProperty DefaultProperty

Ruft die Standardeigenschaft des Serversteuerelements ab, in dem Elemente analysiert werden, oder legt diese fest.Gets or sets the default property for the server control into which the elements are parsed.

TypeId TypeId TypeId TypeId

Ruft bei Implementierung in einer abgeleiteten Klasse einen eindeutigen Bezeichner für dieses Attribute ab.When implemented in a derived class, gets a unique identifier for this Attribute.

(Inherited from Attribute)

Methoden

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Bestimmt, ob das angegebene Objekt mit dem aktuellen Objekt identisch ist.Determines whether the specified object is equal to the current object.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Fungiert als Hashfunktion für das ParseChildrenAttribute-Objekt.Serves as a hash function for the ParseChildrenAttribute object.

GetType() GetType() GetType() GetType()

Ruft den Type der aktuellen Instanz ab.Gets the Type of the current instance.

(Inherited from Object)
IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute()

Gibt einen Wert zurück, der angibt, ob der Wert der aktuellen Instanz der ParseChildrenAttribute-Klasse der Standardwert der abgeleiteten Klasse ist.Returns a value indicating whether the value of the current instance of the ParseChildrenAttribute class is the default value of the derived class.

Match(Object) Match(Object) Match(Object) Match(Object)

Beim Überschreiben in einer abgeleiteten Klasse wird ein Wert zurückgegeben, der angibt, ob diese Instanz einem bestimmten Objekt entspricht.When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(Inherited from Attribute)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Erstellt eine flache Kopie des aktuellen Object.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.Returns a string that represents the current object.

(Inherited from Object)

Explizite Schnittstellenimplementierungen

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Ordnet eine Reihe von Namen einer entsprechenden Reihe von Dispatchbezeichnern zu.Maps a set of names to a corresponding set of dispatch identifiers.

(Inherited from Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Ruft die Typinformationen für ein Objekt ab, mit deren Hilfe die Typinformationen für eine Schnittstelle abgerufen werden können.Retrieves the type information for an object, which can be used to get the type information for an interface.

(Inherited from Attribute)
_Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32)

Ruft die Anzahl der Schnittstellen mit Typinformationen ab, die von einem Objekt bereitgestellt werden (0 oder 1).Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(Inherited from Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Stellt den Zugriff auf von einem Objekt verfügbar gemachte Eigenschaften und Methoden bereit.Provides access to properties and methods exposed by an object.

(Inherited from Attribute)

Gilt für:

Siehe auch