In this article I will explain with an example, how to use Page_ClientValidate function with JavaScript in ASP.Net.
Page_ClientValidate is an ASP.Net JavaScript function in-built which is used to perform ASP.Net validation explicitly i.e. invoking the ASP.Net Validators using JavaScript.
For example, in order to make the RequiredFieldValidator work with OnClientClick we need to make use of Page_ClientValidate JavaScript function in ASP.Net.
 
 
HTML Markup
The HTML Markup consists of an ASP.Net TextBox, a RequiredFieldValidator and a Button which has an OnClientClick event handler attached.
Name:
<asp:TextBox ID="txtName" runat="server" />
<asp:RequiredFieldValidator runat="server" ErrorMessage="Required" ControlToValidate="txtName"></asp:RequiredFieldValidator>
<br />
<br />
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClientClick="return Validate();" />
 
 
Using Page_ClientValidate function with JavaScript in ASP.Net
When the Submit Button is clicked, the Validate JavaScript function is called. The Page_ClientValidate function is called which invokes the ASP.Net validators and if all the validators are valid it returns True.
Ultimately, the JavaScript Confirmation Box is displayed.
<script type="text/javascript">
    function Validate() {
        if (Page_ClientValidate()) {
            return confirm('Do you want to submit data?');
        }
        return false;
    }
</script>
 
 
Demo
 
 
Downloads