Saturday, October 25, 2008

asp.net validation along with classical javascript validation

Sometimes we need to some conditional validations(e.g. depending on multiple fields) or some complex validations which cannot be performed by asp.net validation. For this reason, we need asp.net validation along with javascript validation.

To perform this, we set the OnClientClick property with a value like this - "return isValidForm()". Note, there return keyword must preceed the function call. Otherwise it will not prevent postback whether validation function isValidForm() return true or false.

then the body of the validation function like this -

function isValidForm()
{
/*
calling javascript validation function with return statement
*/
return Page_ClientValidate();
}