ASP.NET How to do Selective Validation

Posted on 2006-05-11
Last Modified: 2010-10-05
I have created a project in ASP.NET with C#.  I want to selectively validate two Drop Down List ddlOne and ddlTwo.  If the user selects an item in ddlOne, then I don't want ddlTwo to be validated, and if a user selects ddlTwo, then I don't want to validate ddlOne.  How can I do this?
Question by:tsmolskow
    LVL 2

    Accepted Solution

    Create a custom valider control. Then switch to the codebehind and look at the two arguments it takes in...

    The second parameter is System.Web.UI.WebControls.ServerValidateEventArgs. Lets call say this is called evtArguments.

    You control if it passes or fails by saying evtArguments.IsValid = (true/false)

    So your logic would be something like.. (sorry this is in but its easy enough to convert)

    If ddlOne.selectedvalue <> "" then
     evtArguments.IsValid = true
    elseif ddlTwo.selectedvalue <> "" then
     evtArguments.IsValid = true
     evtArguments.IsValid = false
    end if

    I really didnt pay too much attention if this logic is 100% correct for your situation but you can get the idea that you can manually control if it passes or fails the validation.

    Hope this helps..

    Author Comment

    Works like a charm - thanks buddy!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Suggested Solutions

    Title # Comments Views Activity
    zeroFront challenge 7 58
    Order table with macro 3 65
    changeXy challenge 13 40
    Path of Workbook 3 30
    This article will show, step by step, how to integrate R code into a R Sweave document
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    760 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

    8 Experts available now in Live!

    Get 1:1 Help Now