asp.netvb.netvalidationvalidationgroup

validation group validations programatically in asp.net with vb.net as code behind


I have a panel, controls in the panel..these controls validated with a validation group.

This panel will show / hide when a dropdown box changes.

Question is...i want to validate all the controls with validation group in the panel

how to write the code


Solution

  • You define validationgroup="Test" on your validators , and you define also this validationgroup="Test" on your Button.

    Sample

         .....
         <asp:requiredfieldvalidator id="NameTextBoxRequiredValidator" 
            controltovalidate="NameTextBox"
            display="Dynamic" 
            text="Please enter your name."
            validationgroup="ForPanel"  <----------------
            runat="server"/>
    
          <asp:button id="SubmitButton"
            text="Submit"
            validationgroup="ForPanel"  <------------------
            runat="server"/>
    

    Nota : Gets or sets the name of the validation group to which this validation control belongs.