Click here to Skip to main content
Click here to Skip to main content

How to disable validation group using javascript

, 22 Nov 2011
Rate this:
Please Sign up or sign in to vote.
Enable/Disable validation group using javascript
script type="text/javascript">        
function HasPageValidators()        
{            
  var hasValidators = false;                      
  try            
  {                
    if (Page_Validators.length > 0)                
      {                    
        hasValidators = true;                
      }            
  }            
  catch (error) { }                      
  return hasValidators;        
}              
 
function ValidationGroupEnable(validationGroupName, isEnable)        
{            
  if (HasPageValidators())            
  {                
    for(i=0; i < Page_Validators.length; i++)                
    {                    
      if (Page_Validators[i].validationGroup == validationGroupName)               
      {
        ValidatorEnable(Page_Validators[i], isEnable);                    
      }                
    }            
  }        
}  
 
<form id="form1"  runat="server">        
  <div>            
  <input type="button" value="Disable required field validators!"  önclick="ValidationGroupEnable('vgRequiredFields', false)" />            <input type="button" value="Enable required field validators!"  önclick="ValidationGroupEnable('vgRequiredFields', true)" />          
  <table>              
  <tr>                  
   <td style="width: 229px">                      
    <asp:Label ID="lblName" runat="server" Text="Name: " />
    <asp:TextBox ID="txtName" runat="server" />                      
    <asp:RequiredFieldValidator ID="rfvName" runat="server" ErrorMessage="*"  ControlToValidate="txtName" ValidationGroup="vgRequiredFields" />
   </td>                                  
  </tr>              
  <tr>                   
   <td style="width: 229px">                       
    <asp:Label ID="lblEmail" runat="server" Text="Email: " />
    <asp:TextBox ID="txtEmail" runat="server"/> 
    <asp:RequiredFieldValidator ID="rfvEmail" runat="server" ErrorMessage="*" ControlToValidate="txtEmail" ValidationGroup="vgRequiredFields" /> 
    <asp:RegularExpressionValidator ID="revEmail" runat="server"ErrorMessage="!" ControlToValidate="txtEmail" ValidationGroup="vgRegularExpressions"ValidationExpression="^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$" />
   </td>              
  </tr>          
  </table>       
 </div> 
</form>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Ramanujam Shankar
Web Developer Mahindra Logisoft Business Solution Limited, Chenn
India India
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web02 | 2.8.140821.2 | Last Updated 23 Nov 2011
Article Copyright 2011 by Ramanujam Shankar
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid