Solved

Required field depends on value of another field

Posted on 2009-06-30
3
237 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

691 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