Solved

Required field depends on value of another field

Posted on 2009-06-30
3
233 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

Suggested Solutions

Title # Comments Views Activity
Scheduled IIS .Net2 AppPools recycle and SQL connection Hangs 33 91
Icons and Colors for Terms 3 24
WKHTMLTOPDF - --disable-smart-shrinking not working 10 37
DateTimepicker 4 33
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 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

16 Experts available now in Live!

Get 1:1 Help Now