BaseValidator.ForeColor Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Recebe ou define a cor da mensagem exibida quando a validação falha.
public:
virtual property System::Drawing::Color ForeColor { System::Drawing::Color get(); void set(System::Drawing::Color value); };
public override System.Drawing.Color ForeColor { get; set; }
member this.ForeColor : System.Drawing.Color with get, set
Public Overrides Property ForeColor As Color
Valor de Propriedade
A que representa a cor da mensagem exibida quando a Color validação falha. A predefinição é Red.
Exemplos
O seguinte exemplo de código demonstra como usar a ForeColor propriedade para mostrar a mensagem de validação em azul.
Importante
Este exemplo tem uma caixa de texto que aceita a entrada do utilizador, o que constitui uma potencial ameaça à segurança. Por defeito, as páginas Web do ASP.NET validam que a entrada do utilizador não inclui elementos de script ou HTML. Para mais informações, consulte Visão Geral dos Exploits de Scripts.
<%@ 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="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>
Observações
Use a ForeColor propriedade para especificar uma cor de texto personalizada para a mensagem apresentada no controlo de validação quando a validação falhar.