24 February 2009

Validating using asp.net validation in custom javascript

Wow,
I just found how easy it is to have custom javascript at the same time using ASP.Net validators to validate user input (Client Side).
In my situation, the ASP.Net validators were not firing because I had hooked custom javascript to a button click.
e.g.
function ValidateAddressAddition()
{
if (confirm('Are you sure you wish to add a previous address?'))
{
return true;
}
return false;
}

The above code will block ASP.Net validation but if I add lines in Red, it would work fine
function ValidateAddressAddition()
{
if (Page_ClientValidate())
{
if (confirm('Are you sure you wish to add a previous address?'))
{
return true;
}
}
return false;
}