mohammedn
mohammedn

Reputation: 2950

Access isvalid property of ASP.NET validators in Javascript

I have read here that any ASP.NET validator has a property called: isvalid. This property can be used in client side to check if the validator successfully passed the validation or not.

I tried to access this property as following but for some reason the code fail:

alert(document.getElementById("validator_clientID").isvalid);

Do you have any idea why this is not working?

Upvotes: 8

Views: 12851

Answers (5)

Barot  Haresh
Barot Haresh

Reputation: 56

Kindly have a look at the solution below that iterates through all validators and display validators which are invalid at the client side

var varray=new Array(); 
for (var i = 0; i < Page_Validators.length; i++)
 {
   if(!Page_Validators[i].isvalid)
    {
      varray.push(Page_Validators[i])
    }
 }
 varray;

You can paste this code in console to get invalid validators

Upvotes: 1

Joe
Joe

Reputation: 1

On client side Javascript:

var controlIsValid = this.document.getElementById("validatorID").attributes.isvalid.value;

Upvotes: 0

Sylar_
Sylar_

Reputation: 46

I found same !

try this document.getElementById('XXX').Validators[0].isvalid It's working for me

Upvotes: 3

Michał Kuliński
Michał Kuliński

Reputation: 1976

Remember to call

IsValid

instead

isvalid

(may vary)

Upvotes: 0

Kelsey
Kelsey

Reputation: 47726

I don't think the isvalid works on a validator control directly as this is a server side validation function. You can fire a validator check for the current page or validation group using the client side javascript function Page_ClientValidate. You can optionally specify a validation group name a parameter. This will return true if all the validation passes.

You can also look at more available client-side functions and how they map to the server side functions on MSDN at:

http://msdn.microsoft.com/en-us/library/yb52a4x0.aspx

Upvotes: 3

Related Questions