Solved

Required field depends on value of another field

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

759 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

21 Experts available now in Live!

Get 1:1 Help Now