Solved

Javascript adn required field validation asp.net

Posted on 2010-11-09
3
435 Views
Last Modified: 2012-06-21
hi,

i am using a required field validation on my dropdownlist. i have two drop downs and would like to hide one of the validators if both items have not been filled out. There should be a way to do this with javascript or JQuery. not sure how to do the test.

Thanks
0
Comment
Question by:JMRFan4Life
3 Comments
 
LVL 41

Assisted Solution

by:guru_sami
guru_sami earned 200 total points
ID: 34094584
Can you give exact scenario when you want to disable.
The idea is you get the two dropdown list by IDs in javascript and then see if the value for them is nothing or some pre-assigned, if so call ValidatorEnable method and disable the validator you want to.

Something like here: http://weblogs.asp.net/gurusarkar/archive/2010/07/26/enable-disable-validator-controls-from-javascript.aspx

If you can provide some of your code, we can get better idea.
0
 
LVL 13

Accepted Solution

by:
devlab2012 earned 300 total points
ID: 34094843
I assume that you have two validators val1 and val2. And a button to submit the form. Try the following implementation:

1. Add onclientclick="custValidate()" for the button.

3. The code for custValidate() function will be:

function custValidate()
{
//enable both validators
ValidatorEnable(val1, true);
ValidatorEnable(val2, true);

//run the validation
ValidatorValidate(val1);
ValidatorValidate(val2);

//check if both the validations fail, disable any one of these
if (val1.isvalid == false && val2.isvalid == false)
{
ValidatorEnable(val2, false);
ValidatorValidate(val2);
}

}
0
 

Author Closing Comment

by:JMRFan4Life
ID: 34094966
I actually used some javascript to get this done. below is my code actually used, but the examples above work jsut as well.

            if (ddlFPGenderChild1.selectedIndex == 0 && ddlFPRelationChild1.selectedIndex == 0) {
              $(rfvrel1valid).css({ "visibility": "visible", "display": "none" });
            };

i use selectedIndex to determine if the dropdowns have been selected or not. This case if first position is shown for both drop downs then hide one.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

828 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