Solved

Required field depends on value of another field

Posted on 2009-06-30
3
234 Views
Last Modified: 2012-05-07
I have a field in a formview which is required only if the user has chosen a certain option from another dropdown on the same form.  For instance, if the user chooses option 1 from the dropdown the second field is required, if they choose option 2 the second field isn't required.

Is there a way to accomplish this with the .net validators or do I have to write some client-side Javascript?

Thanks in advance!
0
Comment
Question by:AX_User
3 Comments
 
LVL 5

Expert Comment

by:rizwanidrees
ID: 24743743
You have to do it with your own script.
0
 
LVL 3

Accepted Solution

by:
tpsl earned 125 total points
ID: 24743745
You will have to write javascript for the same.

Write a javascript onchange event of ddl.

you will not get intellisense for onchange event in html.

in javascript you could use the ValidatorEnable method to enable disable the validator controls.
0
 
LVL 2

Assisted Solution

by:puneetdudeja
puneetdudeja earned 125 total points
ID: 24743835
You can also do it with the .net validators but with the "CustomValidator" validator only.
Use ClientValidationFunction for CustomValidator and set  ControlToValidate to your dropdown containing that values.

In ClientValidation function check the value of your dropdown and it is the value for which the other field is required than set "IsValid" property of argument "e" to false in the ClientValidation function.

ClientValidationFunction(sender,e)
{
     // If drop down value is the one that requires the other field
     // set e.IsValid=false;
}

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

832 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