GLIanimal
asked on
Custom Validator firing, but does not stop the button click
I currently have added a custom validator to my asp.net page. This CV checks to see if the value of a certain ddl is one of 2 values. My code seems to fire, but it continues with the button click code rather than stopping the user and requiring them to select the required value. Am I missing something here?
Thanks
Thanks
CV.Properties; enabled = true, ValidateEmptyText = true.
protected void SubCatCustomValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
if(ddProdCat.SelectedValue != "NEW PRODUCTS" || ddProdCat.SelectedValue != "CUSTOM FABRICATIONS")
{
args.IsValid = false;
SubCatCustomValidator.Text = "**Please Select A Sub Category**";
}
}
protected void SeriesCustomValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
if (ddProdCat.SelectedValue != "NEW PRODUCTS" || ddProdCat.SelectedValue != "CUSTOM FABRICATIONS")
{
args.IsValid = false;
SubCatCustomValidator.Text = "**Please Select A Series**";
}
}
ASKER
The reason i am using a custom validator is due to this item not being required for certain categories. From what I understand/have found is that I can't say if value in ddl = 'whatever' don't validate for the required field validator.
Also, my field can not equal both, so I can't use an 'AND'. That part works fine, it goes in and checks that and sets the value, as I stated above, but I cant get it to break the page.
Also, my field can not equal both, so I can't use an 'AND'. That part works fine, it goes in and checks that and sets the value, as I stated above, but I cant get it to break the page.
ASKER
PS. It previously was a required field, but the customer needs to be able to add items to the categories that do not require a sub category or series.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sweet! Thanks. I knew it was something easy I was totally missing
By the way, why don't you add a RequiredFieldValidator instead of CustomValidator?
Check this example
Open in new window