HtmlGenericControl.TagName Property
Gets or sets the tag name of an element that contains a runat= "server" attribute.
[Visual Basic] Public Shadows Property TagName As String [C#] public new string TagName {get; set;} [C++] public: __property String* get_TagName(); public: __property void set_TagName(String*); [JScript] public hide function get TagName() : String; public function set TagName(String);
Property Value
The tag name of an element.
Remarks
Use this property to programmatically determine the element name of the HTML server control. For example, the TagName property for a server-side <span id="MySpan" runat= "server"/> element contains the value "span".
Example
[Visual Basic, C#, JScript] The following example demonstrates how to use the TagName property to programmatically change a tag name from "Body" to "Font" and back.
[Visual Basic] <%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> <script language="VB" runat="server"> Sub BG_Button_Click(sender As Object, e As EventArgs) Body.Attributes("bgcolor") = ColorSelect.Value End Sub 'BG_Button_Click Sub Font_Button_Click(sender As Object, e As EventArgs) Body.TagName = "Font" Body.Attributes("Color") = ColorSelect.Value End Sub 'Font_Button_Click </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> [C#] <%@ Page Language="C#" AutoEventWireup="True" %> <html> <head> <script language="C#" runat="server"> void BG_Button_Click(Object sender, EventArgs e) { Body.Attributes["bgcolor"] = ColorSelect.Value; } void Font_Button_Click(Object sender, EventArgs e) { 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> [JScript] <%@ 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>
[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
See Also
HtmlGenericControl Class | HtmlGenericControl Members | System.Web.UI.HtmlControls Namespace