views:

1433

answers:

3

Does anyone know how to disable an ASP.NET validator using JavaScript? I'm using javascript style.display = 'none' to disable parts of a web page. However these disabled parts have asp.net validators that are still firing and I need to disable then without doing a round trip to the server. Thanks.

+9  A: 

Use this snippet:

function doSomething()
{
  var myVal = document.getElementById('myValidatorClientID');
  ValidatorEnable(myVal, false); 
}
Andreas Grech
Heads-up: this will not work for ASP.NET 1.1 with Firefox http://stackoverflow.com/questions/3640183/disable-asp-net-1-1-validator-using-javascript-not-working-in-firefox
IrishChieftain
+1  A: 

Additionally, rather than simply hiding elements you could set the Visible property to false...

whateverItem.Visible = false;

This makes that item simply not render to the page, which I believe disables the validation. Someone please correct me if I am wrong.

Mike Fielden
You are correct that it does not render to the page, but that requires a postback whereas Javascript does not.
Mike C.
A: 

Here is detailed article on how to control ASP.NET Validators from JavaScript:

How to control ASP.NET Validator Controls Client Side validation from JavaScript

Roboblob