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
2008-12-30 14:14:25
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
2010-09-07 21:37:39
+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
2009-01-05 15:11:43
You are correct that it does not render to the page, but that requires a postback whereas Javascript does not.
Mike C.
2009-07-01 19:54:39
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
2009-07-04 23:13:36