Sunday, November 2, 2008

ASP.net Custom Validation

ASP.net validation control , such as RequiredFieldValidator , RangeValidator and CompareValidator , is very useful.

But , there will be a day that we need to write a javascript function and used it as CustomValidation.

This is an example of CustomValidation that validate the value entered in a textbox.

The script will need 2 parameters , which will be supplied by CustomValidator control



function CustomValidation(ValidateResult,ObjectToValidate) {
if (ObjectToValidate.Value >= 1 && ObjectToValidate.Value <= 10) {
ObjectToValidate.IsValid = true;
}
else {
ValidateResult.innerText = "Please enter value in range of 1-10 only";
ObjectToValidate.IsValid = false;
}
}



Add a CustomValidator , point ControlToValidate to a textbox and set ClientValidationFunction as "CustomValidation"

9 comments:

BlazekWebDesign said...

Thanks for the shout out at my site. Nice tips as well!

Shea said...

Hi there

techniqueal t. said...

this is a very helpful script! nice tip ^_^

Gab said...

Firstly your site is great and have a lot of information.

Actually I have writing a blog about computer(http://computerblog-gab.blogspot.com). Now I attempt to increase my PR so i need to change link with you.

if you interested with my link exchange offer, plz contact me on :-

gabantiv@yahoo.com

I would appreciate if you deign to exchange link with me.

Thank you.

Anonymous said...

auto insurance missouri You have to almost put your self in their shoes and anticipate what that type of person is going to discard or read. It is difficult but you give it an honest attempt you might get more responses than deletes. Maria , texas car insurance

Car Loan Calculator said...

Thanks for the information....really appreciate it...

Car Loan Calculator said...

Thanks for the information....really appreciate it...

Used Car for Sale said...

alamak cool sgt ni

Malaysia Largest Car Classified said...

good info