A
Adrian Parker
Having a problem with validators.
Because we want to only test whether the current field in a changed event is valid before we process the change code, I have tried
to turn off all validators for the page (all ctrls are in a table), then just enable the one relevant validator, run the
page.validate and then if valid, do the change code. otherwise, skip the change code and then finally enable all the validators
again.
What's happening is that it all seems to work except that if the field fails validation, the page isn't displaying the error
message.. until I change the field again. So on first postback, the error doesn't display, but on 2nd postback it does.
The validator does contain the expected error message and IsValid value after each postback.
'-----------------------------------------------
Public Sub ToggleValidators(ByVal bToggle As Boolean)
Dim bv As BaseValidator
For Each bv In Page.Validators
bv.Enabled = bToggle
Next
End Sub
'Child changed event..
Dim cv As CustomValidator
ToggleValidators(False)
cv = mytable.FindControl(ID + "_validator")
If Not cv Is Nothing Then cv.Enabled = True
Page.Validate()
If Page.IsValid Then
' changed event handling for control ID.
End If
ToggleValidators(True)
'-----------------------------------------------
Hope someone can spot what's wrong with this.
Thanks
Because we want to only test whether the current field in a changed event is valid before we process the change code, I have tried
to turn off all validators for the page (all ctrls are in a table), then just enable the one relevant validator, run the
page.validate and then if valid, do the change code. otherwise, skip the change code and then finally enable all the validators
again.
What's happening is that it all seems to work except that if the field fails validation, the page isn't displaying the error
message.. until I change the field again. So on first postback, the error doesn't display, but on 2nd postback it does.
The validator does contain the expected error message and IsValid value after each postback.
'-----------------------------------------------
Public Sub ToggleValidators(ByVal bToggle As Boolean)
Dim bv As BaseValidator
For Each bv In Page.Validators
bv.Enabled = bToggle
Next
End Sub
'Child changed event..
Dim cv As CustomValidator
ToggleValidators(False)
cv = mytable.FindControl(ID + "_validator")
If Not cv Is Nothing Then cv.Enabled = True
Page.Validate()
If Page.IsValid Then
' changed event handling for control ID.
End If
ToggleValidators(True)
'-----------------------------------------------
Hope someone can spot what's wrong with this.
Thanks