Monday 10 June 2019

ASP.NET - Javascript - Fix Error 'Page_ClientValidate' is undefined

Watch this example on YouTube




To fix it replace

   <script lang="javascript" type="text/javascript">
        function Validate() {
            debugger;
            try {
                var result = Page_ClientValidate('Test');
                return result;
            }
            catch (Error) {
                return true;
            }
        }
    </script>

with


    <title></title>
        <script lang="javascript" type="text/javascript">
        function Validate() {
            debugger;
            try {
                if (typeof (Page_ClientValidate) === 'function') {
                    var result = Page_ClientValidate('Test');
                    return result;
                }
                else {
                    return true;
                }

            }
            catch (Error) {
                return true;
            }
        }
    </script>


whole code

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ASPApplication.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
        <script lang="javascript" type="text/javascript">
        function Validate() {
            debugger;
            try {
                if (typeof (Page_ClientValidate) === 'function') {
                    var result = Page_ClientValidate('Test');
                    return result;
                }
                else {
                    return true;
                }
            }
            catch (Error) {
                return true;
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server" onsubmit="return Validate();">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button" />
   
    </div>
    </form>
</body>
</html>

No comments:

Post a Comment