This is a migrated thread and some comments may be shown as answers.

Client side validation not firing and Page_Validators undefined

26 Answers 1491 Views
Input
This is a migrated thread and some comments may be shown as answers.
Massimiliano
Top achievements
Rank 1
Massimiliano asked on 14 May 2013, 05:28 PM
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>

26 Answers, 1 is accepted

Sort by
0
Massimiliano
Top achievements
Rank 1
answered on 14 May 2013, 07:28 PM
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

0
Marin
Telerik team
answered on 17 May 2013, 12:36 PM
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.
0
Massimiliano
Top achievements
Rank 1
answered on 17 May 2013, 05:43 PM
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.
0
Clement
Top achievements
Rank 1
answered on 23 May 2013, 09:22 AM
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. 
0
Massimiliano
Top achievements
Rank 1
answered on 23 May 2013, 10:14 AM
I feel your pain :)
0
TimTom
Top achievements
Rank 2
answered on 16 Aug 2013, 02:30 PM
Thank you - you are a god!!! :)
0
Chris
Top achievements
Rank 1
answered on 07 Dec 2013, 08:47 PM
YOU ARE MY HERO. Tell me where to send beer.
0
Valerio Natangelo
Top achievements
Rank 1
answered on 14 Dec 2014, 10:05 AM
You are my hero...
0
Massimiliano
Top achievements
Rank 1
answered on 14 Dec 2014, 06:23 PM
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.
0
Joaquín
Top achievements
Rank 2
answered on 11 Mar 2016, 11:21 PM
Oh my god. Thank you very much Massimiliano! This was getting me crazy until I read your post.
0
Massimiliano
Top achievements
Rank 1
answered on 12 Mar 2016, 10:16 AM
Glad this helped ;)
0
Jon
Top achievements
Rank 1
answered on 11 Apr 2016, 08:41 PM
Nearly 3 years since your original discovery...  Thank you!!!
0
Massimiliano
Top achievements
Rank 1
answered on 12 Apr 2016, 02:33 PM
you are welcome! one of the good things of the internet ;)
0
Epic
Top achievements
Rank 1
answered on 07 Dec 2016, 12:19 PM
thanks its works fine ! i know the topic is old but thanks again !
0
Gilles Beraudo
Top achievements
Rank 1
answered on 09 Dec 2016, 04:07 PM

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.

0
Massimiliano
Top achievements
Rank 1
answered on 09 Dec 2016, 09:41 PM
you are welcome  ;)
0
Marin
Telerik team
answered on 12 Dec 2016, 08:15 AM
Hello everyone,

Additional information, troubleshooting tips and guidance on how to properly use unobtrusive validation in ASP.NET Web site with Telerik controls can be found in this help topic:
http://docs.telerik.com/devtools/aspnet-ajax/general-information/troubleshooting/jquery-troubleshooting

There's no need to disable it in the web.config any more.

Regards,
Marin
Telerik by Progress
Telerik UI for ASP.NET AJAX is ready for Visual Studio 2017 RC! Learn more.
0
Siddharth
Top achievements
Rank 1
answered on 17 Feb 2017, 09:52 AM

Thanks a lot man! 

You are truly a Savior!

I tried to resolve this bug and wasted 3-4 Hours and FInally found a solutioin from your side.

Thank you!

 

0
SSirica
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 24 Apr 2018, 06:52 PM
OMG Thank you!!!  This pulled me back from the edge.  
0
Allen
Top achievements
Rank 2
Iron
Veteran
answered on 14 Aug 2019, 01:22 PM
What is the final disposition of this problem?  Should this key always be added or does the whole validation arrangement in a page have to be updated?
0
Allen
Top achievements
Rank 2
Iron
Veteran
answered on 15 Aug 2019, 01:51 AM

I am concerned that I am gettting the same outcome.  However, whether I have the appsetting enabled or not the validators are still not firing.  Is it possible this is due to the version of TElerik I am running?

 

0
Allen
Top achievements
Rank 2
Iron
Veteran
answered on 15 Aug 2019, 01:51 AM
2018.1.117 is my version BTW.  Sorry.
0
Peter Milchev
Telerik team
answered on 19 Aug 2019, 08:32 AM

Hello Allen,

Due to a breaking change in the .NET 4.5 version, this key in the web.config is needed in all 4.5+ projects: 

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

Also, the Telerik version should not have any effect on the behavior of the validation.

What you can check is if the validation is working with a simple ASP controls and verify that the IDs and validation groups are set correctly.

If you still encounter issues only with the Telerik controls and not the regular ASP controls, please prepare a small sample project with a few Telerik TextBoxes and validators where the validation is not working and send it to us in an official support ticket. That would allow us to investigate locally your exact scenario and provide more specific suggestions.

Once we have a solution in the support ticket, we can share the solution here for convenience and better visibility from the community.

Regards, Peter Milchev
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Allen
Top achievements
Rank 2
Iron
Veteran
answered on 19 Aug 2019, 11:05 AM
Gee, nice to know.  Only cost me two days of screwing with these to stumble on this...alas....  I have incorporated it and waddya-know, validators work again.  
0
Allen
Top achievements
Rank 2
Iron
Veteran
answered on 19 Aug 2019, 11:06 AM
And I guess I am wondering why you don't just overcome this on the fly if the directive is missing so old code still works? 
0
Allen
Top achievements
Rank 2
Iron
Veteran
answered on 19 Aug 2019, 11:30 AM
And is this early post in this thread in fact wrong?  It says you don't need to worry about it.  But apparently that is not right. Please mark it bogus!

Additional information, troubleshooting tips and guidance on how to properly use unobtrusive validation in ASP.NET Web site with Telerik controls can be found in this help topic:
http://docs.telerik.com/devtools/aspnet-ajax/general-information/troubleshooting/jquery-troubleshooting

There's no need to disable it in the web.config any more.
Tags
Input
Asked by
Massimiliano
Top achievements
Rank 1
Answers by
Massimiliano
Top achievements
Rank 1
Marin
Telerik team
Clement
Top achievements
Rank 1
TimTom
Top achievements
Rank 2
Chris
Top achievements
Rank 1
Valerio Natangelo
Top achievements
Rank 1
Joaquín
Top achievements
Rank 2
Jon
Top achievements
Rank 1
Epic
Top achievements
Rank 1
Gilles Beraudo
Top achievements
Rank 1
Siddharth
Top achievements
Rank 1
SSirica
Top achievements
Rank 2
Iron
Iron
Veteran
Allen
Top achievements
Rank 2
Iron
Veteran
Peter Milchev
Telerik team
Share this question
or