requiredfieldvalidation for 2 listboxes
-
User needs to choose either of 2 listboxes... How to set a requiredfieldvalidator for this problem? If none of listboxes r selected, requirefieldvalidator will throw a error that none is been selected..Look into the problem!!!
Hi, You can do this simply with javascript. Here is the Code for that: //////// ASPX PAGE CODE /***** JAVASCRIPT FUNCTION *****/ function checkDropDowns() { var ddl1 = document.getElementById('ddl1'); var ddl2 = document.getElementById('ddl2'); if(ddl1.options[0].selected == true && ddl2.options[0].selected == true) { alert("Please Select One Value From Atleast One DropDown Box!!"); return false; } } /****************************/ /****** ASPX PAGE BODY **********/
Select Item Item 1 Item 2 Item 3 Select Item Item 1 Item 2 Item 3
/********** CODE BEHIND FILE ***********/ IN PAGE LOAD EVENT ADD THE FOLLOWING CODE : Button1.Attributes.Add("OnClick","javascript:return checkDropDowns();"); /****************************************/ I hope this will solve your problem Thanks,:) Sushant Duggal.