Título: [SOLUCIONADO] problemas con un CustomValidator no envia el mensaje Publicado por: jorgexl30 en 19 Octubre 2009, 23:01 pm hola bueno esta es mi tercera publicacion espero me puedan ayudar
resulta que tengo un CustomValidator para validar nu,ero de cuotas segun la fecha le hago un seguimiento a la validacion y lohace bien pero no envia el mensaje de error al control tampoco parta el submit de la pagina de antemano muchas gracias (tengo dos controles de error el CustomValidator es el que me da problemas ) en el formulario tengo esto <td align="left" style="width: 358px; height: 2px;"> <asp:DropDownList ID="Cuotas" AutoPostBack="true" runat="server" > <asp:ListItem Text="Cuotas" Selected="True" /> <asp:ListItem Text="1" Value="1" /> <asp:ListItem Text="2" Value="2" /> <asp:ListItem Text="3" Value="3" /> <asp:ListItem Text="4" Value="4" /> <asp:ListItem Text="5" Value="5" /> </asp:DropDownList> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" BackColor="White" ControlToValidate="Cuotas" ErrorMessage="Ingrese N°Cuotas...!" Width="91px"></asp:RequiredFieldValidator> </td> <td align="left" style="width: 358px; height: 2px"> <asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="Cuotas" OnServerValidate="CustomValidator1_ServerValidate" ErrorMessage="La Cuota no es valida ...!" Width="259px" BackColor="White" Font-Size="Medium"></asp:CustomValidator></td> </tr> y el codigo es este Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate Dim numerocuota As Integer Dim fechaAux As Date Dim dias As String Dim ano As String numerocuota = Me.Cuotas.SelectedValue ano = Date.Now.Year If Semestre.Text = "1" Then Select Case numerocuota Case "5" fechaAux = Format("dd/MM/yyyy", "05/04/" & ano) dias = DateDiff(("d"), fechaAux, Date.Now) If dias > 0 Then args.IsValid = False Else args.IsValid = True End If Case "4" fechaAux = Format("dd/MM/yyyy", "05/05/" & ano) dias = DateDiff(("d"), fechaAux, Date.Now) If dias > 0 Then args.IsValid = False Else args.IsValid = True End If Case "3" fechaAux = Format("dd/MM/yyyy", "05/06/" & ano) dias = DateDiff(("d"), fechaAux, Date.Now) If dias > 0 Then args.IsValid = False Else args.IsValid = True End If Case "2" fechaAux = Format("dd/MM/yyyy", "05/07/" & ano) dias = DateDiff(("d"), fechaAux, Date.Now) If dias > 0 Then args.IsValid = False Else args.IsValid = True End If Case "1" fechaAux = Format("dd/MM/yyyy", "05/08/" & ano) dias = DateDiff(("d"), fechaAux, Date.Now) If dias > 0 Then args.IsValid = False Else args.IsValid = True End If End Select End If If Semestre.Text = "2" Then Select Case numerocuota Case "5" fechaAux = Format("dd/MM/yyyy", "05/09/" & ano) dias = DateDiff(("d"), fechaAux, Date.Now) If dias > 0 Then args.IsValid = False Else args.IsValid = True End If Case "4" fechaAux = Format("dd/MM/yyyy", "05/10/" & ano) dias = DateDiff(("d"), fechaAux, Date.Now) If dias > 0 Then args.IsValid = False Else args.IsValid = True End If Case "3" fechaAux = Format("dd/MM/yyyy", "05/11/" & ano) dias = DateDiff(("d"), fechaAux, Date.Now) If dias > 0 Then Response.Write("1") args.IsValid = False Else args.IsValid = True Response.Write("2") End If Response.End() Case "2" fechaAux = Format("dd/MM/yyyy", "05/12/" & ano) dias = DateDiff(("d"), fechaAux, Date.Now) If dias > 0 Then args.IsValid = False Else Modulo.Text = dias End If Case "1" ano = Convert.ToInt16(ano) ano = ano + 1 fechaAux = Format("dd/MM/yyyy", "05/01/" & ano) dias = DateDiff(("d"), fechaAux, Date.Now) If dias > 0 Then args.IsValid = False Else args.IsValid = True End If End Select End If End Sub :( Título: Re: problemas con un CustomValidator no envia el mensaje Publicado por: MANULOMM en 21 Octubre 2009, 00:20 am Asegurate de que la propiedad display sea igual a static o dynamic.
Recuerda que para detener el postback debes preguntar si es valido en el evento que lanza el postback. Código
si no haces esto la validación aunque sea falsa (args.IsValid) continuara la ejecución, debería mostrarte el mensaje pero continuara con la ejecución de código normalmente. Atentamente, Juan Manuel Lombana Medellín - Colombia Título: Re: problemas con un CustomValidator no envia el mensaje Publicado por: MANULOMM en 21 Octubre 2009, 00:52 am algo adicional, si tienes la propiedad ControlToValidate del custom validator con algun control, asegurate de poner la propiedad
Código: ValidateEmptyText="True" para que se lance la validacion siempre ;) ;). Atentamente, Juan Manuel Lombana Medellín - Colombia Título: Re: problemas con un CustomValidator no envia el mensaje Publicado por: jorgexl30 en 21 Octubre 2009, 17:28 pm hola lo voy a retomar y te cuento
Título: Re: problemas con un CustomValidator no envia el mensaje Publicado por: jorgexl30 en 21 Octubre 2009, 17:30 pm juan unaconsulta el autopostabak debe ir en true o false para el dropnlist
jorge Título: Re: problemas con un CustomValidator no envia el mensaje Publicado por: MANULOMM en 21 Octubre 2009, 18:00 pm ps se supone que en true, pero he visto que cuando se lanza el postback por un DropDownList el validador no se lanza, yo le que hago normalemente es que pongo el autopostback en false y agrego un boton sin codigo que diga aceptar al lado del DropDown, el boton cuando se presione lanzara el custom validator, pero el boton no debe llevar nada de codigo ps el objetivo es que solo haga el postback.
Atentamente, Juan Manuel Lombana Medellín - Colombia Título: Re: problemas con un CustomValidator no envia el mensaje Publicado por: Hadess_inf en 24 Octubre 2009, 13:59 pm Si se hace el postback ya no habria necesidad de validar puesto que ya se sobre entiende que se selecciono algun item. xD
Título: Re: problemas con un CustomValidator no envia el mensaje Publicado por: MANULOMM en 24 Octubre 2009, 15:18 pm pero segun vi en la logica no solo depende del item, por ser un custom validator valida la fecha contra el item o algo asi, si fuese un RequeridFieldValidator si, pero aqui hay una logica asociada al objeto, a algunas veces no se me lanza con el PostBack que hace el dropdownlist.
Atentamente, Juan Manuel Lombana Medellín - Colombia Título: Re: problemas con un CustomValidator no envia el mensaje Publicado por: jorgexl30 en 26 Octubre 2009, 13:58 pm hola gracias lo solucione me faltaba el
if IsValid then end if muy bueno el foro e solucionado varios problemas como soy nuevo en asp.net no lo domino mucho muchas gracias (poste otro problema que tengo ocn una grilla..) ;-) |