Java script page validation Page_clientValidate()
While asnwering the asp.net forums questions, i found many thread related to javascript page valiation function Page_ClientValidate() , i would like to breifly dicussed the client side validation here in this post.
There are two page validation
-
Server side (page.isvalid)
-
Client side (Page_ClientValidate())
-
Page.IsValid
If Page.IsValid Then
-
'Write add Code
'Do Work With Database
Else
'Page Is Not Valid
'Fire Some Validation
-
End If
Page.Isvalid is server side validation when user hit the server button and page is post back, if the page is valid Page.IsValid Return true , other wise its return false.The Page.IsValid will return false untill the page is valid.
-
Client Validation Page_ClientValidate
The Job of this function is to check the page is it valid if any of the validator is not valid this function return false otherwise it return true ,
so you have to write code like
<script language="javascript">
function fireUserNameExistsValidation() {if (Page_ClientValidate()) {
// Page is Ok
//Submit it To The Server
return true
} else {//Page is Not Valid
//Return False
return false
}
}
</script>
If you are using more than one Validation Groups in page, so you need to explicitly specify the group
Like
if(Page_ClientValidate("GroupName")){
//Code Here
}