CustomValidator.IsValid value not pushed up to Page.IsValid

CustomValidator.IsValid value not pushed up to Page.IsValid

Post by Chris Becke » Sat, 13 Jul 2002 04:59:39



My custom validator checks a value and sets its IsValid property
accordingly.  In the case when it is set to false, how does that get rolled
into the Page.IsValid property, which is read only?  After the
ServerValidate action happens, the buttons OnClick event happens and
continues on its merry way because Page.IsValid = true even though the
custom validator's IsValid property = false
 
 
 

CustomValidator.IsValid value not pushed up to Page.IsValid

Post by Chris Becke » Sat, 13 Jul 2002 08:02:51


I think I found it. My original code looked like this:

    Private Sub valEmailExists_ServerValidate(ByVal source As System.Object,
ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles
valEmailExists.ServerValidate
        If AccountExists(txtEmail.Text) Then
            valEmailExists.IsValid = False
        Else
            valEmailExists.IsValid = True
        End If
    End Sub

But the value of valEmailExists was not bubbled up to the Page.IsValid().
I thought it might help to use the args parameter and lo and behold, this
works:

    Private Sub valEmailExists_ServerValidate(ByVal source As System.Object,
ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles
valEmailExists.ServerValidate
        If AccountExists(args.Value) Then
            args.IsValid = False
        Else
            args.IsValid = True
        End If
    End Sub


Quote:> My custom validator checks a value and sets its IsValid property
> accordingly.  In the case when it is set to false, how does that get
rolled
> into the Page.IsValid property, which is read only?  After the
> ServerValidate action happens, the buttons OnClick event happens and
> continues on its merry way because Page.IsValid = true even though the
> custom validator's IsValid property = false