WebControl.Style プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
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
プロパティ値
Web サーバー コントロールの外部タグにレンダリングする HTML スタイル属性を含む CssStyleCollection 。
- 属性
例
次の例では、 Style プロパティを使用して、ページ上の Label コントロールを非表示または表示する方法を示します。
注
次のコード サンプルでは、単一ファイルコード モデルを使用します。分離コード ファイルに直接コピーした場合、正しく動作しない可能性があります。 このコード サンプルは、.aspx拡張子が付いている空のテキスト ファイルにコピーする必要があります。 Web フォーム コード モデルの詳細については、「Web フォーム ページ コード モデル ASP.NET」を参照してください。
<%@ 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" など) によって設定されたスタイル値は、このコレクション内の対応する値を自動的にオーバーライドします。
このコレクションに設定された値は、厳密に型指定されたスタイル プロパティによって自動的に反映されません。