Sergej Andrejev
Sergej Andrejev

Reputation: 9413

Developing ASP.NET validator with client-side validation

How to define client-side logic in new ASP.NET validator (not CustomValidator). Can you point me to articles where whole process is described?

Upvotes: 1

Views: 166

Answers (2)

tro
tro

Reputation: 524

This article goes through the process of creating a new custom validator by deriving from BaseValidator instead of CustomerValidator.

The trick for getting ASP.NET to execute your JS code is this (in AddAttributesToRender()):

if(this.RenderUplevel) {
    string clientID = this.ClientID;
    Page.ClientScript.RegisterExpandoAttribute(clientID, 
        "evaluationfunction", 
        "MultipleFieldsValidatorEvaluateIsValid");
}

ASP.NET will then call MultipleFieldsValidatorEvaluateIsValid().

Also, see How do I hook up javascript to my CustomValidator control in .Net

Upvotes: 1

Daniel Liuzzi
Daniel Liuzzi

Reputation: 17167

In the ASP.NET MVC world, there's a wonderful validation framework called xVal, which I have used with great success. Apparently there is a port for ASP.NET, xVal for WebForms. I have not used it, but it might be worth a try. Good luck!

Upvotes: 0

Related Questions