Control.AddParsedSubObject(Object) 메서드

정의

XML 또는 HTML 요소가 구문 분석되었음을 서버 컨트롤에 알리고 서버 컨트롤의 ControlCollection 개체에 요소를 추가합니다.

protected:
 virtual void AddParsedSubObject(System::Object ^ obj);
protected virtual void AddParsedSubObject (object obj);
abstract member AddParsedSubObject : obj -> unit
override this.AddParsedSubObject : obj -> unit
Protected Overridable Sub AddParsedSubObject (obj As Object)

매개 변수

obj
Object

구문 분석한 요소를 나타내는 Object입니다.

예제

다음 예제는 이 컨트롤의 여는 태그와 닫는 태그 사이에 선언된 요소가 웹 서버 컨트롤인지 확인하기 위해 메서드를 사용하는 AddParsedSubObject 사용자 지정 서버 컨트롤입니다 TextBox . 개체인 경우 개체itemsArrayList 추가됩니다. 재정의된 CreateChildControls 메서드가 호출되면 해당 메서드를 반복 ArrayList 하여 해당 메서드의 각 개체를 ControlCollection 사용자 지정 서버 컨트롤에 추가합니다.

중요

이 예제에는 사용자 입력을 허용하는 텍스트 상자가 있으므로 보안상 위험할 수 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.

// Custom ControlBuilder class. Interprets nested tag name "myitem" as a textbox. 
public class MyControlBuilder : ControlBuilder 
{
   public override Type GetChildControlType(String tagName,
                                       IDictionary attributes)
   {
      if (String.Compare(tagName, "myitem", true) == 0) 
      {
         return typeof(TextBox);
      }
      return null;
   }
}

[ 
ControlBuilderAttribute(typeof(MyControlBuilder)) 
]
public class MyControl : Control
{
   // Store all the controls specified as nested tags.
   private ArrayList items = new ArrayList();
   
   // This function is internally invoked by IParserAccessor.AddParsedSubObject(Object).
   protected override void AddParsedSubObject(Object obj) 
   {
      if (obj is TextBox) 
      {
         items.Add(obj);
      }
   }

   // Override 'CreateChildControls'. 
   protected override void CreateChildControls()
   {
      System.Collections.IEnumerator myEnumerator = items.GetEnumerator();
      while(myEnumerator.MoveNext())
          this.Controls.Add((TextBox)myEnumerator.Current);
   }
}    
' Custom ControlBuilder class. Interprets nested tag name "myitem" as a textbox.
Public Class MyControlBuilder
   Inherits ControlBuilder

   Public Overrides Function GetChildControlType(tagName As String, _
                             attributes As IDictionary) As Type
      If String.Compare(tagName, "myitem", True) = 0 Then
         Return GetType(TextBox)
      End If
      Return Nothing
   End Function
End Class

<ControlBuilderAttribute(GetType(MyControlBuilder))> Public Class MyControl
   Inherits Control
   ' Stores all the controls specified as nested tags.
   Private items As New ArrayList()

   ' This function is internally invoked by IParserAccessor.AddParsedSubObject(Object).
   Protected Overrides Sub AddParsedSubObject(obj As Object)
      If TypeOf obj Is TextBox Then
         items.Add(obj)
      End If
   End Sub

  ' Override 'CreateChildControls'.
   Protected Overrides Sub CreateChildControls()
      Dim myEnumerator As System.Collections.IEnumerator = items.GetEnumerator()
      While myEnumerator.MoveNext()
         Me.Controls.Add(CType(myEnumerator.Current, TextBox))
      End While
   End Sub
End Class

설명

재정의하지 않는 한 이 메서드는 자동으로 서버 컨트롤의 ControlCollection 개체에 개체를 추가 LiteralControl 합니다. 이 컬렉션은 속성을 통해 Control.Controls 액세스할 수 있습니다.

적용 대상

추가 정보