• 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?
0
crcsupport
Asked:
crcsupport
1 Solution
 
EMB01Commented:
Traditionally, you could do this with client side and server side validation.  On the client side, we would use jQuery as follows:
$(document).ready(function(){
  $('#myForm').submit(function(){
    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.
0
 
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
http://www.4guysfromrolla.com/articles/073102-1.aspx

Alan ";0)
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