ASP.NET validation for condition.

Posted on 2012-08-20
Last Modified: 2012-08-20
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?
Question by:crcsupport
    LVL 14

    Expert Comment

    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.
    LVL 26

    Accepted Solution

    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

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on could not pull conte…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now