Freigeben über


HtmlGenericControl.TagName-Eigenschaft

Ruft den Namen des durch das HtmlGenericControl-Steuerelement dargestellten HTML-Elements ab oder legt diesen fest.

Namespace: System.Web.UI.HtmlControls
Assembly: System.Web (in system.web.dll)

Syntax

'Declaration
Public Property TagName As String
'Usage
Dim instance As HtmlGenericControl
Dim value As String

value = instance.TagName

instance.TagName = value
public string TagName { get; set; }
public:
property String^ TagName {
    String^ get ();
    void set (String^ value);
}
/** @property */
public String get_TagName ()

/** @property */
public void set_TagName (String value)
public function get TagName () : String

public function set TagName (value : String)

Eigenschaftenwert

Der Tagname eines Elements.

Hinweise

Verwenden Sie diese Eigenschaft für das programmgesteuerte Bestimmen des Elementnamens für das HTML-Serversteuerelement. Die TagName-Eigenschaft eines serverseitigen <span id="MySpan" runat= "server"/>-Elements enthält z. B. den Wert "span".

Beispiel

Im folgenden Codebeispiel wird veranschaulicht, wie mit der TagName-Eigenschaft programmgesteuert ein Tagname von "Body" in "Font" und wieder zurück geändert werden kann.

<%@ Page Language="VB" %>

<!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 BG_Button_Click(ByVal sender As Object, ByVal e As System.EventArgs)

    Body.Attributes("bgcolor") = ColorSelect.Value

  End Sub

  Protected Sub Font_Button_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    
    Body.TagName = "Font"
    Body.Attributes("Color") = ColorSelect.Value

  End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>HtmlGenericControl Example</title> 
</head>
 
 <body id="Body" 
       runat="server"> 

     <h3>HtmlGenericControl Example</h3>

     <form runat="server">
     <div> 
       <p>
       Select a background color for the page: <p>
       <select id="ColorSelect" 
               runat="server">
           <option>White</option>
           <option>LightBlue</option>
           <option>LightGreen</option>
           <option>Yellow</option>
       </select>
       <br>
       <input type="submit" 
              runat="server"
              value="Change Background Color" 
              OnServerClick="BG_Button_Click" id="Submit1">
       <input type="submit" 
              runat="server" 
              value="Change Font Color" 
              OnServerClick="Font_Button_Click" id="Submit2">
     </div>
     </form>
 
 </body>
 </html>
<%@ Page Language="C#" %>

<!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 BG_Button_Click(object sender, EventArgs e)
  {
    Body.Attributes["bgcolor"] = ColorSelect.Value;
  }

  protected void Font_Button_Click(object sender, EventArgs e)
  {
    Body.TagName = "Font";
    Body.Attributes["Color"] = ColorSelect.Value;
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>HtmlGenericControl Example</title> 
</head>
 
 <body id="Body" 
       runat="server"> 

     <h3>HtmlGenericControl Example</h3>

     <form runat="server">
     <div>
       <p>
       Select a background color for the page: <p>
       <select id="ColorSelect" 
               runat="server">
           <option>White</option>
           <option>LightBlue</option>
           <option>LightGreen</option>
           <option>Yellow</option>
       </select>
       <br>
       <input type="submit" 
              runat="server"
              value="Change Background Color" 
              OnServerClick="BG_Button_Click" id="Submit1">
       <input type="submit" 
              runat="server" 
              value="Change Font Color" 
              OnServerClick="Font_Button_Click" id="Submit2">
     </div>
     </form>
 
 </body>
 </html>
<%@ Page Language="JScript" AutoEventWireup="True" %>

<html>
 <head>
 
    <script language="JSCRIPT" runat="server">
    function BG_Button_Click(sender : Object, e : EventArgs){
        Body.Attributes["bgcolor"] = ColorSelect.Value
    }

    function Font_Button_Click(sender : Object, e : EventArgs){
        Body.TagName = "Font"
        Body.Attributes["Color"] = ColorSelect.Value
    }
 
  </script>
 
 </head>
 
 <body id="Body" runat="server">
 
     <h3>HtmlGenericControl Sample</h3>
 
     <form runat="server">
 
       <p>
       Select a background color for the page: <p>
       <select id="ColorSelect" runat="server">
           <option>White</option>
           <option>LightBlue</option>
           <option>LightGreen</option>
           <option>Yellow</option>
       </select>
       <br>
       <input type="submit" runat="server" Value="Change Background Color" OnServerClick="BG_Button_Click">
       <input type="submit" runat="server" Value="Change Font Color" OnServerClick="Font_Button_Click">
     </form>
 
 </body>
 </html>
 

Plattformen

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

HtmlGenericControl-Klasse
HtmlGenericControl-Member
System.Web.UI.HtmlControls-Namespace

Weitere Ressourcen

HTML-Serversteuerelemente