HtmlGenericControl.TagName Property

 

Gets or sets the name of the HTML element represented by the HtmlGenericControl control.

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

public string TagName { get; set; }

Property Value

Type: System.String

The tag name of an element.

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".

The following code example demonstrates how to use the TagName property to programmatically change a tag name from "Body" to "Font" and back.

<%@ 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 id="form1" runat="server">
     <div>
       <br />
       Select a background color for the page: <br />
       <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>

.NET Framework
Available since 1.1
Return to top
Show: