Nov 21, 2010

Disable ASP.Net Validator with Javascript

ASP.Net validators like RequireField Validator, Compare Validator, RangeValidator etc. works on server-side. but sometime you have the requirement where you have some customized validation on client-side and depending on some logic you want to enable/disable ASP.Net Validator on client-side.

Let's have an example with code to disable ASP.Net Validator using JavaScript

Scenario:
We have a checkbox Password Required on web-form where depending on check/un-check we have to enable/disable requiredfield validator for Password Textbox field.

Below are the two JavaScript methods to perform the same. You can use any of the method.

function disableValidator()
{
  var myVal = document.getElementById('myValidatorClientID');
  ValidatorEnable(myVal, false);
}

function disableValidator()
{
  var myval = document.getElememtById('validator.ClientId');
  myval.style.cssText="";
  myval.style.display='none';
  myval.style.accelerator=true;
}

    Choose :
  • OR
  • To comment
No comments:
Write comments