• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 331
  • Last Modified:

ASP.NET validation for condition.

I'm trying to validate inputs conditionally.

There are one TextBox and one DropDownList.
If The TextBox is filled, then DropDownList needs to be selected. How can I put this condition on what validation control on DropDownList?
1 Solution
Traditionally, you could do this with client side and server side validation.  On the client side, we would use jQuery as follows:
    if ($('#myTextbox').val())
      if ($('#myDropdown').val() == NULL)
        alert('please select an option from the dropdown');

Open in new window

On the server side, just use conditions like you would normally and throw an exception or something if the correct value has not been sent.
Alan WarrenCommented:
Hi crcsupport,

I'd recommend having a look at the CustomValidator control.

This article by Scott Mitchell should get you off in the right direction:
Using the CustomValidator Control

Alan ";0)

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now