Solved

Javascript adn required field validation asp.net

Posted on 2010-11-09
3
431 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

743 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

15 Experts available now in Live!

Get 1:1 Help Now