How to Invoke required field validator through javascript in

In this post I will show you how to invoke required field validator through java script in
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ReqJs.aspx.cs" Inherits="ReqJs" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
    <script type="text/javascript">
        function PerformCheck() {
            if (Page_ClientValidate()) {
                //Do some more stuff here
                alert("Page Is Valid");

    <form id="form1" runat="server">
        <asp:TextBox runat="server" ID="txtFirstName"></asp:TextBox>
        <asp:RequiredFieldValidator ErrorMessage="*" Text="Please Enter first name" ControlToValidate="txtFirstName"
            runat="server" /><br />
        <asp:TextBox runat="server" ID="txtLastName"></asp:TextBox>
        <asp:RequiredFieldValidator ErrorMessage="*" Text="Please enter last name" ControlToValidate="txtLastName"
            runat="server" /><br />
        <input type="submit" id="btnSubmit" onclick="PerformCheck();" value="Validate" />

No comments:

Post a Comment