views:

341

answers:

1

I am using jQuery and jQuery.validate plugin to validate ASP.NET pages, since I found jQuery Validation plugin better than ASP.NET validation controls.

I have used This validation code for Login and simultaneously for other pages like register and many others.

//.NET code
Dim jsValidate As String = String.Format("Validators.validateLogin('{0}','{1}');", _
txtUsername.ClientID, txtPassword.ClientID)
btnLogin.Attributes.Add("onclick", jsValidate)

//javascript code    
Validators.validateLogin = function(txtUsername, txtPassword) {
    $('#aspnetForm').validate();
    $('#'+txtUsername).rules('add', {
        required: true
    });
    $('#'+txtUsername).rules('add', {
        required: true
    });
}

Now the problem I am facing is if I have multiple controls on a page which require or not require validation. How to handle that situation. Bcoz once someone clicked on Login button it starts validation function and on pressing on some other button in some other control, it stuck with current validation. I wish if jQuery validation plugin can handle some groups like ASP.NET validationGroup, it could be a lot easier. Anyone have suggestions?

Thanks in Advance

A: 

You might try overloading CSS classes as validation groups. Basically you could filter out the controls whose class didn't match a specific pattern and only validate against those. Kind of a hack but it might just work for you.

Craig