views:

641

answers:

3

Hi all,

Pretty simple question.

I have a few ASP RequiredFieldValdators checking some text boxes.

Out of the box, it checks validation when a button is pressed, basically disabling it unless all fields are met.

I also have a listbox with a bunch of data points, which load new data into the text boxes that are being validated.

I want to make sure the user can't switch data points before all required fields are met. How can I "disable" the listbox (via validation) similar to how the buttons are "disabled"

Please feel free to ask for clarification

+1  A: 

The asp.net validators do not provide this kind of functionality to conditionally disable the controls. You will need to write your own validator (pretty tough, or see Peter Blum). Better handle it in blur event handler for the textbox.

 <script type="text/javascript">
   $(document).ready(function(){
      $("#<%=yourTextbox.ClientID%>").blur(function(){
         $("#<%=yourDropDown.ClientID%>").attr("disabled","disabled");
         ValidateInputs();//You will validate inputs in this function
      });
   });
 </script>

 <script type="text/javascript">
  function ValidateInputs(){
     //.....Validations......
     if(validattions okay){ 
        $("#<%=yourDropDown.ClientID%>").attr("disabled","");
      }
  }
 </script>

PS:- I'm supposing you are using jQuery, if not please get some time and visit jQuery.com and give it a try.

TheVillageIdiot
A: 

I just set CauseValidation="true" for the listbox. This prevented me from changing data points when the current fields were invalid

Thanks all

Erik Ahlswede
A: 

Write CauseValidation="false" on the cancel button of apsx page.

Vasini