IValidator.ErrorMessage Propriedade
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Quando implementado por uma classe, obtém ou define o texto da mensagem de erro gerada quando a condição que está sendo validada falha.
public:
property System::String ^ ErrorMessage { System::String ^ get(); void set(System::String ^ value); };
public string ErrorMessage { get; set; }
member this.ErrorMessage : string with get, set
Public Property ErrorMessage As String
Valor da propriedade
A mensagem de erro a ser gerada.
Exemplos
Importante
Este exemplo tem uma caixa de texto que aceita a entrada do usuário, que é uma possível ameaça à segurança. Por padrão, ASP.NET páginas da Web validam que a entrada do usuário não inclui elementos html ou script. Para obter mais informações, consulte Visão geral de explorações de script.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>IValidator Example demonstrating IsValid & ErrorMessage</title>
<script language="C#" runat="server">
void Button_Click(Object sender, EventArgs e)
{
// Generating the random number.
Random rand_s = new Random();
myCompareValidate.ValueToCompare = rand_s.Next(1, 10).ToString();
// Setting the ErrorMessage.
myCompareValidate.ErrorMessage="Try Again!!";
myCompareValidate.Validate();
// Check for Validity of control.
if ((myCompareValidate.IsValid) && (myTextBox.Text != ""))
{
labelOutput.Text = "You guessed correctly!!";
labelOutput.ForeColor = System.Drawing.Color.Blue;
}
else
{
labelOutput.Text = "You guessed poorly";
labelOutput.ForeColor = System.Drawing.Color.Black;
}
labelOutput.Text += "<br /><br />" + "The number is: " +
myCompareValidate.ValueToCompare;
}
</script>
</head>
<body>
<form runat="server" id="myForm">
<h3>IValidator Example demonstrating IsValid & ErrorMessage</h3>
<h5>Guess!! a number between 1 and 10 :</h5>
<asp:TextBox id="myTextBox" runat="server" />
<asp:CompareValidator id="myCompareValidate"
ControlToValidate="myTextBox" ValueToCompare="0"
EnableClientScript="False" Type="Integer" Text="*"
runat="server" />
<br />
<asp:Button Text="Submit" OnClick="Button_Click" runat="server" />
<br />
<asp:Label id="labelOutput" runat="server" />
<br />
<asp:ValidationSummary id="Summary1" runat="server" />
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>IValidator Example demonstrating IsValid & ErrorMessage</title>
<script language="VB" runat="server">
Sub Button_Click(sender As [Object], e As EventArgs)
' Generating a random number.
Dim rand_s As New Random()
myCompareValidate.ValueToCompare = rand_s.Next(1, 10).ToString()
' Set the ErrorMessage.
myCompareValidate.ErrorMessage = "Try Again!!"
myCompareValidate.Validate()
' Check for Validity of control.
If myCompareValidate.IsValid And myTextBox.Text <> "" Then
labelOutput.Text = "You guessed correctly!!"
labelOutput.ForeColor = System.Drawing.Color.Blue
Else
labelOutput.Text = "You guessed poorly"
labelOutput.ForeColor = System.Drawing.Color.Black
End If
labelOutput.Text += "<br /><br />" + "The number is: " + _
myCompareValidate.ValueToCompare
End Sub 'Button_Click
</script>
</head>
<body>
<form runat="server" id="myForm">
<h3>IValidator Example demonstrating IsValid & ErrorMessage</h3>
<h5>Guess!! a number between 1 and 10:</h5>
<asp:TextBox id="myTextBox" runat="server" />
<asp:CompareValidator id="myCompareValidate"
ControlToValidate="myTextBox" ValueToCompare="0"
EnableClientScript="False" Type="Integer" Text="*"
runat="server" />
<br />
<asp:Button Text="Submit" OnClick="Button_Click" runat="server" />
<br />
<asp:Label id="labelOutput" runat="server" />
<br />
<asp:ValidationSummary id="Summary1" runat="server" />
</form>
</body>
</html>
Comentários
ASP.NET desenvolvedores acessam essa propriedade declarativamente na marca de abertura de um controle de servidor de validação. Para obter mais informações, consulte Sintaxe de controle do servidor de validação.
Aplica-se a
Confira também
Comentários
https://aka.ms/ContentUserFeedback.
Em breve: Ao longo de 2024, eliminaremos os problemas do GitHub como o mecanismo de comentários para conteúdo e o substituiremos por um novo sistema de comentários. Para obter mais informações, consulteEnviar e exibir comentários de