Notifica al controllo server che un elemento, XML o HTML, è stato analizzato e aggiunge l'elemento all'oggetto ControlCollection del controllo server.
Assembly: System.Web (in System.Web.dll)
Protected Overridable Sub AddParsedSubObject ( _ obj As Object _ )
protected virtual void AddParsedSubObject( Object obj )
protected: virtual void AddParsedSubObject( Object^ obj )
abstract AddParsedSubObject : obj:Object -> unit override AddParsedSubObject : obj:Object -> unit
Parametri
- obj
- Tipo: System.Object
Oggetto Object che rappresenta l'elemento sottoposto ad analisi.
A meno che non venga sottoposto a override, questo metodo aggiunge automaticamente gli oggetti LiteralControl all'oggetto ControlCollection del controllo server. È possibile accedere a questo insieme tramite la proprietà Control.Controls.
Nell'esempio che segue vien illustrato un controllo server personalizzato che utilizza il metodo AddParsedSubObject per determinare se gli elementi dichiarati tra i tag di apertura e di chiusura del controllo sono controlli server Web TextBox. Se lo sono, vengono aggiunti a un oggetto ArrayList, items. Quando viene chiamato il metodo CreateChildControls sottoposto a override, viene fatto scorrete l'elenco ArrayList e ogni oggetto contenuto viene aggiunto all'insieme ControlCollection del controllo server personalizzato.
Nota sulla sicurezza
|
|---|
|
L'esempio include una casella di testo che accetta l'input dell'utente e rappresenta quindi una potenziale minaccia alla sicurezza. Per impostazione predefinita, le pagine Web ASP.NET verificano che l'input dell'utente non includa script o elementi HTML. Per ulteriori informazioni, vedere Cenni preliminari sugli attacchi tramite script. |
' 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
// 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); } }
.NET Framework
Supportato in: 4, 3.5, 3.0, 2.0, 1.1, 1.0Windows 7, Windows Vista SP1 o versione successiva, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (componenti di base del server non supportati), Windows Server 2008 R2 (componenti di base del server supportati con SP1 o versione successiva), Windows Server 2003 SP2
.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema di .NET Framework.
Nota sulla sicurezza