Click to See Complete Forum and Search --> : Validation problems


Funkymonkey
08-23-2005, 05:29 AM
If no category is chosen off my list (the selected index is 0) My form displays the correct error message but it still updates the database. I have this:

Private Sub CustomValidator2_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator2.ServerValidate
If rfqCategoryDropDown.SelectedIndex = 0 Then
args.IsValid = False
Else : args.IsValid = True
End If
End Sub

But it's obviously wrong.
Please help me :)

Funkymonkey
08-24-2005, 07:48 AM
Ok I have this now:
Sub Category_validate(ByVal Sender As Object, ByVal Args As ServerValidateEventArgs)
If rfqCategoryDropDown.SelectedIndex > 0 Then
Args.IsValid = True
Else
Args.IsValid = False
End If
End Sub

Which stops the database being updated but keeps saying that I need to select a category when I already have.

A1ien51
08-24-2005, 01:13 PM
Have you tried to debug the code adding break points and stepping through the code to see what is happening. If you dropdowns are databinded, are they being binded on post back?

Eric

Funkymonkey
08-25-2005, 07:13 AM
My dropdown list is not binded on postback. Should it be?