Los foros del Guille

MKN Reservas (Maro - Kayak Nerja)


Kayak Maro - Rutas y alquiler de kayak y tabla

Si no encuentras respuesta, puedes buscar en el sitio del Guille

Google
 
Selecciona el foro y pulsa en mostrar:     Mostrar 
De tu inter�s (algunos de los avisos publicados)

01/feb./2019

Los moderadores, MVP y administradores podrán seguir editando, respondiendo o creando nuevos mensajes

Con idea de que puedan ayudar a responder e ir cerrando mensajes ;-)

  Foro: .NET General Cantidad:  Desde:   Hasta:    Aplicar   Responder 
Respuestas a: 55744 - Validating - Validated
IDAsuntoFechaNick 
55744 Validating - Validated30/08/11 14:33RobWare   
Saludo al foro
Deseo entender el proposito de el evento Validated, comprendo el proposito de Validating, por que permite Cancelar el cambio de foco si no se cumplen las condiciones que se programen pero no veo que proposito tiene Validated.

Agradeceria me aclararan esto por favor
IDAsuntoFechaNick 
55770 Re: Validating - Validated (Resp: 55744)06/09/11 22:05klo¥   
Hola aquí está un ejemplo práctico. Me parece el código esta bien explicito, el método validated se utiliza para ejecutar la función que mejor te parezca cuando tengas validado el campo:
(Fuente MSDN)



private void textBox1_Validating(object sender,
System.ComponentModel.CancelEventArgs e)
{
string errorMsg;
if(!ValidEmailAddress(textBox1.Text, out errorMsg))
{
// Cancel the event and select the text to be corrected by the user.
e.Cancel = true;
textBox1.Select(0, textBox1.Text.Length);

// Set the ErrorProvider error with the text to display.
this.errorProvider1.SetError(textBox1, errorMsg);
}
}

private void textBox1_Validated(object sender, System.EventArgs e)
{
// If all conditions have been met, clear the ErrorProvider of errors.
errorProvider1.SetError(textBox1, "");
}
public bool ValidEmailAddress(string emailAddress, out string errorMessage)
{
// Confirm that the e-mail address string is not empty.
if(emailAddress.Length == 0)
{
errorMessage = "e-mail address is required.";
return false;
}

// Confirm that there is an "@" and a "." in the e-mail address, and in the correct order.
if(emailAddress.IndexOf("@") > -1)
{
if(emailAddress.IndexOf(".", emailAddress.IndexOf("@") ) > emailAddress.IndexOf("@") )
{
errorMessage = "";
return true;
}
}

errorMessage = "e-mail address must be valid e-mail address format.\n" +
"For example '[email protected]' ";
return false;
}


También podrias hacerlo con un "if-else" en el evento validating y así te olvidarías de usar el validated. Ejemplo:

Private Sub NombreTextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles NombreTextBox.Validating
If Me.NombreTextBox.TextLength = 0 Then
Me.ErrorProvider1.SetError(NombreTextBox, "Este campo no puede estar en blanco")
Else
Me.ErrorProvider1.SetError(NombreTextBox, Nothing)
End If
End Sub


Si esta respuesta resuelve tu duda, por favor pulsa en la de este mensaje. Gracias.

 
(c) Guillermo 'guille' Som, 2005-2026  - foros.elGuille v1.0.6.3 (01/Jun/2021 12:45 GMT +2)  - (ASP.NET v4.0.30319.42000)
 
La hora GMT del servidor es: 14/06/2026 07:52:35 GMT