HtmlTextWriter.TagKey Proprietà
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.
Ottiene o imposta il HtmlTextWriterTag valore per l'elemento di markup specificato.
protected:
property System::Web::UI::HtmlTextWriterTag TagKey { System::Web::UI::HtmlTextWriterTag get(); void set(System::Web::UI::HtmlTextWriterTag value); };
protected System.Web.UI.HtmlTextWriterTag TagKey { get; set; }
member this.TagKey : System.Web.UI.HtmlTextWriterTag with get, set
Protected Property TagKey As HtmlTextWriterTag
Valore della proprietà
Elemento di markup di cui viene eseguito il rendering del tag di apertura.
Eccezioni
Impossibile impostare il valore della proprietà.
Esempio
Nell'esempio di codice seguente viene illustrata una versione sottoposta a override del RenderBeforeContent metodo in una classe che deriva dalla HtmlTextWriter classe . Usa il valore della TagKey proprietà per determinare se un controllo server che utilizza l'oggetto personalizzato HtmlTextWriter esegue il rendering di un <label> elemento di markup. In caso affermativo, viene restituito un <font> elemento con un color attributo impostato su red per modificare la formattazione del <label> testo dell'elemento.
// Override the RenderBeforeContent method to write
// a font element that applies red to the text in a Label element.
virtual String^ RenderBeforeContent() override
{
// Check to determine whether the element being rendered
// is a label element. If so, render the opening tag
// of the font element; otherwise, call the base method.
if ( TagKey == HtmlTextWriterTag::Label )
{
return "<font color=\"red\">";
}
else
{
return __super::RenderBeforeContent();
}
}
// Override the RenderBeforeContent method to write
// a font element that applies red to the text in a Label element.
protected override string RenderBeforeContent()
{
// Check to determine whether the element being rendered
// is a label element. If so, render the opening tag
// of the font element; otherwise, call the base method.
if (TagKey == HtmlTextWriterTag.Label)
{
return "<font color=\"red\">";
}
else
{
return base.RenderBeforeContent();
}
}
' Override the RenderBeforeContent method to write
' a font element that applies red to the text in a Label element.
Protected Overrides Function RenderBeforeContent() As String
' Check to determine whether the element being rendered
' is a label element. If so, render the opening tag
' of the font element; otherwise, call the base method.
If TagKey = HtmlTextWriterTag.Label Then
Return "<font color=""red"">"
Else
Return MyBase.RenderBeforeContent()
End If
End Function 'RenderBeforeContent
Commenti
La TagKey proprietà è di uso solo per le classi che ereditano dalla HtmlTextWriter classe . È consigliabile leggere o impostare la TagKey proprietà solo in una chiamata al RenderBeginTag metodo. Questa è l'unica volta che viene impostata su un valore coerente.