WebControl.Style プロパティ
Web サーバー コントロールの外側のタグにスタイル属性として表示されるテキスト属性のコレクションを取得します。
Public ReadOnly Property Style As CssStyleCollection
[C#]
public CssStyleCollection Style {get;}
[C++]
public: __property CssStyleCollection* get_Style();
[JScript]
public function get Style() : CssStyleCollection;
プロパティ値
Web サーバー コントロールの外側のタグに表示される HTML スタイル属性を示す System.Web.UI.CssStyleCollection 。
解説
Style コレクションを使用して、Web サーバー コントロールの外側のタグに表示されるスタイル属性を管理します。このプロパティは、すべてのコントロールですべてのブラウザに表示されます。
メモ スタイル属性をサポートしないブラウザは、表示された HTML を無視します。
厳密に型指定されたスタイル プロパティ (BackColor="Red" など) を使用して設定されたスタイル値はすべて、このコレクション内の該当の値を自動的にオーバーライドします。
このコレクションに設定された値は、厳密に型指定されたスタイル プロパティによって自動的に反映されません。
使用例
[Visual Basic, C#, JScript] Style プロパティを使用して、ページに Label コントロールを表示したり、非表示にしたりする方法の例を次に示します。
<%@ Page Language="VB" AutoEventWireup="True" %>
<html>
<head>
<script language="VB" 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>
</head>
<body>
<h3>Style Property of a Web Control</h3>
<form runat="server">
<asp:Label id="Label1" Text="This is a label control."
BorderStyle="Solid" runat="server"/>
<p>
<asp:Button id="Button1" Text="Click to hide/unhide the above label"
OnClick="Button1_Click" runat="server"/>
</form>
</body>
</html>
[C#]
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>
<script language="C#" runat="server">
void Button1_Click(Object sender, EventArgs e) {
Label1.Style["visibility"]= ((Label1.Style["visibility"]=="hidden")?"show":"hidden");
}
</script>
</head>
<body>
<h3>Style Property of a Web Control</h3>
<form runat="server">
<asp:Label id="Label1" Text="This is a label control."
BorderStyle="Solid" runat="server"/>
<p>
<asp:Button id="Button1" Text="Click to hide/unhide the above label"
OnClick="Button1_Click" runat="server"/>
</form>
</body>
</html>
[JScript]
<%@ Page Language="JScript" AutoEventWireup="True" %>
<html>
<head>
<script language="JSCRIPT" runat="server">
function Button1_Click(sender : Object, e : EventArgs){
if(Label1.Style["visibility"] == "hidden")
Label1.Style["visibility"] = "show"
else
Label1.Style["visibility"] = "hidden"
}
</script>
</head>
<body>
<h3>Style Property of a Web Control</h3>
<form runat="server">
<asp:Label id="Label1" Text="This is a label control."
BorderStyle="Solid" runat="server"/>
<p>
<asp:Button id="Button1" Text="Click to hide/unhide the above label"
OnClick="Button1_Click" runat="server"/>
</form>
</body>
</html>
[C++] C++ のサンプルはありません。Visual Basic、C#、および JScript のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ
参照
WebControl クラス | WebControl メンバ | System.Web.UI.WebControls 名前空間 | System.Web.UI.CssStyleCollection