Control.AddParsedSubObject(Object) Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Notifica al controllo server che un elemento, XML o HTML, è stato analizzato e aggiunge l'elemento all'oggetto del ControlCollection controllo server.
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)
Parametri
Esempio
L'esempio seguente è un controllo server personalizzato che utilizza il AddParsedSubObject metodo per determinare se gli elementi dichiarati tra i tag di apertura e chiusura di questo controllo sono TextBox controlli server Web. In caso affermativo, vengono aggiunti a un ArrayList oggetto , items. Quando viene chiamato il metodo sottoposto a ControlCollection overrideCreateChildControls, scorre l'oggetto ArrayList e aggiunge ogni oggetto al controllo del server personalizzato.
Importante
In questo esempio è presente una casella di testo che accetta l'input dell'utente, che rappresenta una potenziale minaccia per la sicurezza. Per impostazione predefinita, ASP.NET pagine Web verificare che l'input dell'utente non includa elementi SCRIPT o HTML. Per altre informazioni, vedere Cenni preliminari sugli exploit di script.
// 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
Commenti
A meno che non si esegua l'override, questo metodo aggiunge LiteralControl automaticamente oggetti all'oggetto del ControlCollection controllo server. Questa raccolta è accessibile tramite Control.Controls la proprietà .