Client side validation not firing and Page_Validators undefined

17 posts, 0 answers
  1. Massimiliano
    Massimiliano avatar
    185 posts
    Member since:
    Oct 2012

    Posted 14 May 2013 Link to this post

    As briefly explained in the topic I can't seem to have client side asp.net validators to work. Server side is all ok, infacat since the Page_Validators is undefined, the Page_IsValid is always true (clientside) so the client validation always pass BUT server side, after the postback that shouldn't occur, I get the correct error messages reported.

    I copied exactly your example on demo page of RadInput validation do do further testing but with no results (I even stripped it down a basic 1 textbox + 1 validator, I tryed with standard asp textboxes, I searched the web for 4 hours now finding all kind of answers even in this forum, all with no luck).

    Things I can say in advance:

    - The .axd script resources all loads correctly (checked both in Google Chrome developers console and Firefox Firebug consol. No 404 or 500 errors)
    - The ScriptResources.axd starts with those public js variables (no hint at Page_Validators there is it normal?)

    var Page_ValidationVer = "125";
    var Page_IsValid = true;
    var Page_BlockSubmit = false;
    var Page_InvalidControlToBeFocused = null;
    var Page_TextTypes = /^(text|password|file|search|tel|url|email|number|range|color|datetime|date|month|week|time|datetime-local)$/i;


    - Checking with Google Chrome developers tools console for alert(Page_Validators.length) returns ReferenceError: Page_Validators is not defined
    - If I set in the web.config <add key="Telerik.ScriptManager.TelerikCdn" value="Enabled" /> (instead of "Disabled") I also experience a js error: Uncaught ReferenceError: $telerik is not defined This doesn't happen in my real code btw, just happens on the page I copy/pasted from your on-line example to make tests (I will report the code down here). This means that somehow I fixed that second bug in my real project but I don't remember how.
    - I tryed with both CDN enabled and disabled in the RadScriptManager.
    - I tryed with both your Jquery and with Google CDN served JQuery (1.9.1)

    I really don't know where else look at... after 4/5 unsuccessfull hours at a simple task like validation should be, even in the simpliest scenarios I tested, I really give up. Please give me some hint on where to look for more.
    Here is the code:

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="test.aspx.vb" Inherits="Test" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <head runat="server">
        <title></title>
        <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" CdnSettings-TelerikCdn="Enabled" />
    </head>
    <body>
        <form id="form1" runat="server">
        <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
        <telerik:RadSkinManager ID="QsfSkinManager" runat="server" ShowChooser="true" />
        <telerik:RadFormDecorator ID="QsfFromDecorator" runat="server" DecoratedControls="All" EnableRoundedCorners="false" />
        <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">
            <fieldset>
                <legend>Registration form</legend>
                <br/>
                <table border="0" cellpadding="5">
                    <colgroup>
                        <col width="100"/>
                        <col width="500"/>
                    </colgroup>
                    <tr class="FormContainer">
                        <td>
                            Name:
                        </td>
                        <td>
                            <telerik:RadTextBox ID="RadTextBox1" runat="server"></telerik:RadTextBox>
                            <asp:RequiredFieldValidator ID="TextBoxRequiredFieldValidator" runat="server" Display="Dynamic"
                                ControlToValidate="RadTextBox1" ErrorMessage="The textbox can not be empty!"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr class="FormContainer">
                        <td>
                            Age:
                        </td>
                        <td>
                            <telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server" Type="Number" NumberFormat-DecimalDigits="0">
                            </telerik:RadNumericTextBox>
                            <asp:RequiredFieldValidator ID="NumercTextBoxRequiredFieldValidator" runat="server"
                                Display="Dynamic" ControlToValidate="RadNumericTextBox1" ErrorMessage="Please, select an year number!"></asp:RequiredFieldValidator>
                            <asp:RangeValidator ID="NumericTextBoxRangeValidator" runat="server" ControlToValidate="RadNumericTextBox1"
                                ErrorMessage="Year number should be a non negative less than 50." Display="Dynamic"
                                MaximumValue="50" MinimumValue="0" Type="Double"></asp:RangeValidator>
                        </td>
                    </tr>
                    <tr class="FormContainer">
                        <td valign="top">
                            Phone:
                        </td>
                        <td>
                            <telerik:RadMaskedTextBox ID="RadMaskedTextBox1" runat="server" Mask="(###)-######">
                            </telerik:RadMaskedTextBox>
                            <asp:RequiredFieldValidator Display="Dynamic" ID="MaskedTextBoxRequiredFieldValidator"
                                runat="server" ErrorMessage="Please, enter a phone number." ControlToValidate="RadMaskedTextBox1"></asp:RequiredFieldValidator>
                            <asp:RegularExpressionValidator Display="Dynamic" ID="MaskedTextBoxRegularExpressionValidator"
                                runat="server" ErrorMessage="Format is (###)-######" ControlToValidate="RadMaskedTextBox1"
                                ValidationExpression="\(\d{3}\)-\d{6}"></asp:RegularExpressionValidator>
                        </td>
                    </tr>
                    <tr class="FormContainer">
                        <td valign="top">
                            Email
                        </td>
                        <td>
                            <telerik:RadTextBox ID="Radtextbox2" runat="server"></telerik:RadTextBox>
                            <asp:RegularExpressionValidator ID="emailValidator" runat="server" Display="Dynamic"
                                ErrorMessage="Please, enter valid e-mail address." ValidationExpression="^[\w\.\-]+@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*(\.[a-zA-Z]{2,3}){1,2}$"
                                ControlToValidate="Radtextbox2">
                            </asp:RegularExpressionValidator>
                            <asp:RequiredFieldValidator ID="Requiredfieldvalidator1" runat="server" Display="Dynamic"
                                ControlToValidate="Radtextbox2" ErrorMessage="Please, enter an e-mail!"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr class="FormContainer">
                        <td>
                            Hire Date:
                        </td>
                        <td>
                            <telerik:RadDateInput ID="RadDateInput1" runat="server" DateFormat="d" MinDate="01/01/1990"
                                MaxDate="01/01/3000"></telerik:RadDateInput>
                            <asp:RangeValidator ID="DateInputRangeValidator" runat="server" ControlToValidate="RadDateInput1"
                                ErrorMessage="Choose a date between 5th of January 2005 and 1st of September 2005"
                                Display="Dynamic" MaximumValue="2005-09-01-00-00-00" MinimumValue="2005-01-05-00-00-00"></asp:RangeValidator>
                            <asp:RequiredFieldValidator ID="PickerRequiredFieldValidator" runat="server" Display="Dynamic"
                                ControlToValidate="RadDateInput1" ErrorMessage="Please select a date"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                </table>
                <br/>
                <br/>
                <asp:CheckBox ID="CheckBox1" runat="server" CssClass="CheckBox" Text="Client Side Validation" Checked="True"
                    AutoPostBack="True"></asp:CheckBox>
                <br/>
                <br/>
                <asp:Button ID="Button1" runat="server" Text="Postback"></asp:Button>
                <input type="reset" value="Reset"/>
            </fieldset>
        </telerik:RadAjaxPanel>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server"></telerik:RadAjaxLoadingPanel>
        </form>
    </body>
    </html>

    The VB code is taken exactly from your example as well:

    Imports System
    Imports System.Collections
    Imports System.ComponentModel
    Imports System.Data
    Imports System.Drawing
    Imports System.Web
    Imports System.Web.SessionState
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Web.UI.HtmlControls
     
    Partial Public Class test
        Inherits System.Web.UI.Page
        Private Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
            MaskedTextBoxRequiredFieldValidator.EnableClientScript = CheckBox1.Checked
            DateInputRangeValidator.EnableClientScript = CheckBox1.Checked
            PickerRequiredFieldValidator.EnableClientScript = CheckBox1.Checked
            TextBoxRequiredFieldValidator.EnableClientScript = CheckBox1.Checked
            NumercTextBoxRequiredFieldValidator.EnableClientScript = CheckBox1.Checked
            MaskedTextBoxRegularExpressionValidator.EnableClientScript = CheckBox1.Checked
            NumericTextBoxRangeValidator.EnableClientScript = CheckBox1.Checked
            Requiredfieldvalidator1.EnableClientScript = CheckBox1.Checked
            emailValidator.EnableClientScript = CheckBox1.Checked
        End Sub
    End Class

    Thanks in advance... I really had other frustrating similar issues that went on for hours, but finally come to spot a solution. This time I'm really knocked down.

    EDIT: as a side note I tryed an even more "minimalistic" test wit .NET script manager instead of RadScriptManager and it works perfectly. Checking in the Google js console for alert(Page_Validators.lenght); also returns correctly: 1
    So the issue must be somewhere in the RadScriptManager OR in the RadAjax solution I guess.
    This is the code:

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="test2.aspx.vb" Inherits="test2" %>
     
    <!DOCTYPE html>
     
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:TextBox ID="test" runat="server"></asp:TextBox>
                <asp:RequiredFieldValidator ID="TextBoxRequiredFieldValidator" runat="server" Display="Dynamic"
                    ControlToValidate="test" ErrorMessage="The textbox can not be empty!"></asp:RequiredFieldValidator>
                <asp:Button ID="but" runat="server" Text="submit" />
            </div>
        </form>
    </body>
    </html>

  2. Massimiliano
    Massimiliano avatar
    185 posts
    Member since:
    Oct 2012

    Posted 14 May 2013 Link to this post

    Ok... after 1 hour more of narrowing and research i found the problem.
    What really blows my mind away is this: since validation is a basic task, ajax is widespread in each form and ASP.NET 4.5 is out since a while.... how is it possible that only me and another poor guy on asp.net forums, buried in nowhere post-land, had this issue?!
    How can it be?

    Short story is that the issue is related to ASP.NET 4.5 "new" unobtrusive validation feature.
    It seems that with this feature enabled if you just add a scriptmanager to the page (you don't even have to use ajax or update paneles or such... just add an empty ASP.NET scriptmanager) client side validation won't work anymore.
    First... how can it be? What's the point of this new tech if I can't even add a scriptmanager of it's incompatible with jquery 1.9+

    Second... is this feature enabled by default in 4.5 as a target framework?! If it so I go back to the start... how can it be that only I had this problem?

    The solution: 
    Just add in the web.config 

    <appSettings>
        <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
    </appSettings>

    This will use "old style" non HTML5 validation and WILL work with ajax and JQuery 1.9.1

    Where I found an hint just seconds before suicide:
    http://forums.asp.net/t/1876231.aspx/1?ASP+Net+4+5+Validation+Controls+not+working+with+AJAX+ToolkitScriptManager1

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Marin
    Admin
    Marin avatar
    1045 posts

    Posted 17 May 2013 Link to this post

    Hi,

     We are aware of this problem. It is a general configuration issue between the new unobtrusive ASP.NET 4.5 validation and jQuery. Basically the new validation that is indeed enabled by the default requires a certain script resource mapping to jQuery and if it is missing you get the Page_Validators undefined error. We are also researching the problem further to see if it is possible to improve the RadControls behavior in this specific scenario.
    More information regarding the issue as well as workarounds can also be found at the following links:
    http://stackoverflow.com/questions/12452109/asp-net-2012-unobtrusive-validation-with-jquery

    http://connect.microsoft.com/VisualStudio/feedback/details/735928/in-asp-net-web-application-visual-basic-the-requiredfieldvalidator-doest-work

    Greetings,
    Marin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  5. Massimiliano
    Massimiliano avatar
    185 posts
    Member since:
    Oct 2012

    Posted 17 May 2013 Link to this post

    Thank you Martin.
    Sometimes you get struck in such "basilar" nonsenses where it seems no one else did, that you really start to wonder if the language and framework you are coding with are the same of the other million people around.
  6. Clement
    Clement avatar
    1 posts
    Member since:
    Apr 2008

    Posted 23 May 2013 Link to this post

    Thank you so much. I was having a similar problem after i added an AJAX script to check for username availability on my registration form. Everything was working fine until then. Although the script worked, the validations within the UpdatePanel were no longer firing! Just adding that line in my web config solved it. I had tried everything i could think of for a day and a half. Thank you. 
  7. Massimiliano
    Massimiliano avatar
    185 posts
    Member since:
    Oct 2012

    Posted 23 May 2013 Link to this post

    I feel your pain :)
  8. TimTom
    TimTom avatar
    1 posts
    Member since:
    Nov 2012

    Posted 16 Aug 2013 Link to this post

    Thank you - you are a god!!! :)
  9. Chris
    Chris avatar
    8 posts
    Member since:
    Jan 2012

    Posted 07 Dec 2013 Link to this post

    YOU ARE MY HERO. Tell me where to send beer.
  10. Valerio Natangelo
    Valerio Natangelo avatar
    1 posts
    Member since:
    Mar 2010

    Posted 14 Dec 2014 in reply to Massimiliano Link to this post

    You are my hero...
  11. Massimiliano
    Massimiliano avatar
    185 posts
    Member since:
    Oct 2012

    Posted 14 Dec 2014 Link to this post

    I'm happy to see that after all this time this topic can still be useful to someone. You are welcome.
    This is one of the nicest thing of the web.
  12. Joaquín
    Joaquín avatar
    27 posts
    Member since:
    Jan 2012

    Posted 11 Mar in reply to Massimiliano Link to this post

    Oh my god. Thank you very much Massimiliano! This was getting me crazy until I read your post.
  13. Massimiliano
    Massimiliano avatar
    185 posts
    Member since:
    Oct 2012

    Posted 12 Mar in reply to Joaquín Link to this post

    Glad this helped ;)
  14. Jon
    Jon avatar
    35 posts
    Member since:
    Sep 2013

    Posted 11 Apr Link to this post

    Nearly 3 years since your original discovery...  Thank you!!!
  15. Massimiliano
    Massimiliano avatar
    185 posts
    Member since:
    Oct 2012

    Posted 12 Apr Link to this post

    you are welcome! one of the good things of the internet ;)
  16. Epic
    Epic avatar
    2 posts
    Member since:
    Dec 2016

    Posted 2 days and 18 hours ago Link to this post

    thanks its works fine ! i know the topic is old but thanks again !
  17. Gilles Beraudo
    Gilles Beraudo avatar
    1 posts
    Member since:
    Sep 2006

    Posted 14 hours ago Link to this post

    Thanks so much for sharing your solution, Massimiliano.

    This is still so relevant after 3 years!

     

    @Telerik: any feedback from Ms connect? I was unable to reach your feedback on Ms site.

  18. Massimiliano
    Massimiliano avatar
    185 posts
    Member since:
    Oct 2012

    Posted 9 hours ago Link to this post

    you are welcome  ;)
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017