検証が失敗したときに表示されるメッセージの色を取得または設定します。
名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文
'宣言
Public Overrides Property ForeColor As Color
'使用
Dim instance As BaseValidator
Dim value As Color
value = instance.ForeColor
instance.ForeColor = value
public override Color ForeColor { get; set; }
public:
virtual property Color ForeColor {
Color get () override;
void set (Color value) override;
}
/** @property */
public Color get_ForeColor ()
/** @property */
public void set_ForeColor (Color value)
public override function get ForeColor () : Color
public override function set ForeColor (value : Color)
適用できません。
プロパティ値
検証が失敗したときに表示されるメッセージの色を表す System.Drawing.Color。既定値は Color.Red です。
解説
ForeColor プロパティを使用して、検証が失敗したときに検証コントロール内に表示するメッセージ テキストのカスタム カラーを指定します。
使用例
ForeColor プロパティを使用して、検証メッセージを青で表示するコード例を次に示します。
セキュリティに関するメモ : |
|---|
この例には、ユーザー入力を受け付けるテキスト ボックスがあります。これにより、セキュリティが脆弱になる可能性があります。既定では、ASP.NET Web ページによって、ユーザー入力にスクリプトまたは HTML 要素が含まれていないかどうかが検証されます。詳細については、「スクリプトによる攻略の概要」を参照してください。 |
<%@ Page Language="VB" AutoEventWireup="False" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SubmitButton.Click
If Page.IsValid Then
MessageLabel.Text = "Page submitted successfully."
Else
MessageLabel.Text = "There is an error on the page."
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Validator Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Validator Example</h3>
Enter a number from 1 to 10.
<asp:textbox id="NumberTextBox"
runat="server"/>
<asp:rangevalidator id="NumberCompareValidator"
controltovalidate="NumberTextBox"
enableclientscript="False"
type="Integer"
display="Dynamic"
errormessage="Please enter a value from 1 to 10."
maximumvalue="10"
minimumvalue="1"
text="*"
forecolor="Blue"
runat="server"/>
<asp:requiredfieldvalidator id="TextBoxRequiredValidator"
controltovalidate="NumberTextBox"
enableclientscript="False"
display="Dynamic"
errormessage="Please enter a value."
text="*"
forecolor="Blue"
runat="server"/>
<br /><br />
<asp:button id="SubmitButton"
text="Submit"
runat="server"/>
<br /><br />
<asp:label id="MessageLabel"
runat="server"/>
<br /><br />
<asp:validationsummary
id="ErrorSummary"
runat="server"/>
</form>
</body>
</html>
<%@ 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 Button_Click(Object sender, EventArgs e)
{
if (Page.IsValid)
{
MessageLabel.Text = "Page submitted successfully.";
}
else
{
MessageLabel.Text = "There is an error on the page.";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Validator Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Validator Example</h3>
Enter a number from 1 to 10.
<asp:textbox id="NumberTextBox"
runat="server"/>
<asp:rangevalidator id="NumberCompareValidator"
controltovalidate="NumberTextBox"
enableclientscript="False"
type="Integer"
display="Dynamic"
errormessage="Please enter a value from 1 to 10."
maximumvalue="10"
minimumvalue="1"
text="*"
forecolor="Blue"
runat="server"/>
<asp:requiredfieldvalidator id="TextBoxRequiredValidator"
controltovalidate="NumberTextBox"
enableclientscript="False"
display="Dynamic"
errormessage="Please enter a value."
text="*"
forecolor="Blue"
runat="server"/>
<br /><br />
<asp:button id="SubmitButton"
text="Submit"
onclick="Button_Click"
runat="server"/>
<br /><br />
<asp:label id="MessageLabel"
runat="server"/>
<br /><br />
<asp:validationsummary
id="ErrorSummary"
runat="server"/>
</form>
</body>
</html>
<%@ Page Language="JScript" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
function Button_Click(sender, e : EventArgs)
{
if (Page.IsValid)
{
MessageLabel.Text = "Page submitted successfully.";
}
else
{
MessageLabel.Text = "There is an error on the page.";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Validator Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Validator Example</h3>
Enter a number from 1 to 10.
<asp:textbox id="NumberTextBox"
runat="server"/>
<asp:rangevalidator id="NumberCompareValidator"
controltovalidate="NumberTextBox"
enableclientscript="False"
type="Integer"
display="Dynamic"
errormessage="Please enter a value from 1 to 10."
maximumvalue="10"
minimumvalue="1"
text="*"
forecolor="Blue"
runat="server"/>
<asp:requiredfieldvalidator id="TextBoxRequiredValidator"
controltovalidate="NumberTextBox"
enableclientscript="False"
display="Dynamic"
errormessage="Please enter a value."
text="*"
forecolor="Blue"
runat="server"/>
<br /><br />
<asp:button id="SubmitButton"
text="Submit"
onclick="Button_Click"
runat="server"/>
<br /><br />
<asp:label id="MessageLabel"
runat="server"/>
<br /><br />
<asp:validationsummary
id="ErrorSummary"
runat="server"/>
</form>
</body>
</html>
プラットフォーム
Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition
Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。
バージョン情報
.NET Framework
サポート対象 : 3.0,2.0,1.1,1.0
参照
関連項目
BaseValidator クラス
BaseValidator メンバ
System.Web.UI.WebControls 名前空間
System.Drawing.Color
セキュリティに関するメモ :