WebControl.Style プロパティ

定義

Web サーバー コントロールの外側のタグにスタイル属性として表示されるテキスト属性のコレクションを取得します。

public:
 property System::Web::UI::CssStyleCollection ^ Style { System::Web::UI::CssStyleCollection ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Web.UI.CssStyleCollection Style { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Style : System.Web.UI.CssStyleCollection
Public ReadOnly Property Style As CssStyleCollection

プロパティ値

CssStyleCollection

Web サーバー コントロールの外側のタグに表示される HTML スタイル属性を示す CssStyleCollection

属性

次の例は、プロパティを使用して、ページ上の Style コントロールを非表示または表示 Label する方法を示しています。

注意

次のコード サンプルでは、シングル ファイル コード モデルを使用します。分離コード ファイルに直接コピーした場合、正しく動作しない場合があります。 このコード サンプルは、拡張子が .aspx の空のテキスト ファイルにコピーする必要があります。 Web Forms コード モデルの詳細については、「ページ コード モデルの ASP.NET Web Forms」を参照してください。

<%@ 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">
 
    void Button1_Click(Object sender, EventArgs e)
    {
        if (Label1.Style["visibility"] == "hidden")
            Label1.Style["visibility"] = "show";
        else
            Label1.Style["visibility"] = "hidden";
    }
 
</script>
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" runat="server">
    <title>Style Property of a Web Control</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
 
        <h3>Style Property of a Web Control</h3>
 
        <asp:Label id="Label1" Text="This is a label control." 
            BorderStyle="Solid" runat="server"/>

        <p>
            <asp:Button id="Button1" 
                Text="Click to hide or unhide the label"
                OnClick="Button1_Click" runat="server"/>
        </p>

    </div>
    </form>
</body>
</html>
<%@ 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">
 
    Sub Button1_Click(sender As Object, e As EventArgs)
        If Label1.Style("visibility") = "hidden" Then
            Label1.Style("visibility") = "show"
        Else
            Label1.Style("visibility") = "hidden"
        End If
    End Sub
 
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" runat="server">
    <title>Style Property Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
 
        <h3>Style Property of a Web Control</h3>
 
        <asp:Label id="Label1" Text="This is a label control." 
            BorderStyle="Solid" runat="server"/>

        <p>
            <asp:Button id="Button1" Text="Click to hide or unhide the label"
                OnClick="Button1_Click" runat="server"/>
        </p>

    </div>
    </form>
</body>
</html>

注釈

このコレクションを Style 使用して、Web サーバー コントロールの外側のタグにレンダリングされるスタイル属性を管理します。 このプロパティは、すべてのコントロールのすべてのブラウザーに表示されます。

注意

スタイル属性をサポートしていないブラウザーでは、レンダリングされた HTML は無視されます。

厳密に型指定されたスタイル プロパティ (たとえば) を使用して設定されたスタイル値は、 BackColor="Red"このコレクション内の対応する値を自動的にオーバーライドします。

このコレクションに設定された値は、厳密に型指定されたスタイル プロパティによって自動的に反映されません。

適用対象

こちらもご覧ください