次の方法で共有


HtmlGenericControl.TagName プロパティ

runat= "server" 属性を含む要素のタグ名を取得または設定します。

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);

プロパティ値

要素のタグ名。

解説

このプロパティを使用して、HTML サーバー コントロールの要素名をプログラムによって決定します。たとえば、サーバー側の <span id="MySpan" runat= "server"/> 要素の TagName プロパティには、値 "span" が格納されます。

使用例

[Visual Basic, C#, JScript] TagName プロパティを使用して、プログラムからタグ名を "Body" から "Font" に変更してから、元に戻す方法を次の例に示します。

 
<%@ 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++] C++ のサンプルはありません。Visual Basic、C#、および JScript のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

HtmlGenericControl クラス | HtmlGenericControl メンバ | System.Web.UI.HtmlControls 名前空間