Click here to Skip to main content
15,906,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I am trying to validate my page,once something is entered in the textbox but I am getting this:
Quote:
ReferenceError: Page_ClientValidate is not defined


This is my code:

XML
<script src="scripts/jquery-1.9.1.js"></script>
     <script type="text/javascript">
        $(function () {
            BtnSave();
        });
        function BtnSave() {
            $('#btnSave').on("click", function (e) {
                e.preventDefault();
                if (Page_ClientValidate()) {
                    alert("Page validated!");
                }
            });
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RFVtxtFirstName" runat="server" ControlToValidate="txtFirstName" InitialValue="0"
            ErrorMessage="First Name is required" Display="Dynamic" Enabled="false">
        </asp:RequiredFieldValidator>
        <br />
        <input id="btnSave" type="button" value="Save" class="send action-btn" />
    </div>
    </form>
</body>


can someone help resolve this issue
Posted
Updated 26-Mar-14 21:18pm
v2
Comments
ravikhoda 27-Mar-14 3:27am    
please try and apply validation group to your Validator and button control.
El Dev 27-Mar-14 3:42am    
you mean like this <asp:TextBox ID="txtFirstName" runat="server">
<asp:RequiredFieldValidator ID="RFVtxtFirstName" runat="server" ControlToValidate="txtFirstName" InitialValue="0"
ErrorMessage="First Name is required" Display="Dynamic" Enabled="false" ValidationGroup="button">

<br />
<input id="btnSave" type="button" value="Save" class="send action-btn" ValidationGroup="button" />
if so it is still not working , I have tried it.

1 solution

1.The problem is that you are trying to invoke an event method that run on your web server directly from javascript (from client). You have no access to that method in this way, you have to use AJAX call like in the next example:

JavaScript
$.ajax({
        type: "POST",
        url: action, //Your URL to an action from your server code!
        data: { paramName1: paramValue1, ... paramNameN: paramValueN},
        success: function (resultData) {
            var result = resultData.result;
            //manage your result
            //...
        },
        dataType: "json"
    });


You can see example in the next articles: Invoke Server Methods From Client Side Using jQuery AJAX in ASP.NET[^]
Calling a C# method using jQuery on the client side[^]

2.If you problem is related with client side validation of the user input, you forgot to add and use validation group in your form:

XML
<div >
                        <asp:ValidationSummary ID="form1ValidationSummary" runat="server"                             ValidationGroup="Form1ValidationGroup"/>
</div>
<div>
        <asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RFVtxtFirstName" runat="server" ControlToValidate="txtFirstName" InitialValue="0"
            ErrorMessage="First Name is required" ValidationGroup="Form1ValidationGroup">
        </asp:RequiredFieldValidator>
        <br />
        <input id="btnSave" type="button" value="Save" class="send action-btn" ValidationGroup="Form1ValidationGroup" />
</div>
 
Share this answer
 
v5
Comments
El Dev 27-Mar-14 3:48am    
What? I am not getting you...Am working on my local server not web server!!
and I do not understand the code you post!
Raul Iloc 27-Mar-14 4:00am    
1.A web application is running on "Web Server" (could be your server, a host server, etc).
2.The user is accessing the page by using a browser, and this is the client.
3.My code is an example of AJAX call used for direct access from client browser to the application that are running on the web server.
Raul Iloc 27-Mar-14 4:41am    
See my updates to solution!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900