Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValidatorCalloutExtender with CustomValidator causes an error if the httpRuntime setting is equal to 4.5 #45

Closed
DavidIQ opened this issue Mar 31, 2016 · 6 comments

Comments

@DavidIQ
Copy link

DavidIQ commented Mar 31, 2016

We have set the following for all pages based on suggestions given in another reported issue so that things work well with jQuery:
Page.UnobtrusiveValidationMode = UnobtrusiveValidationMode.WebForms;

I'm getting the following error when pairing a ValidatorCalloutExtender with a CustomValidator:
Uncaught Sys.ArgumentUndefinedException: Sys.ArgumentUndefinedException: Value cannot be undefined. Parameter name: id

Upon further tracing through the JavaScript I've found that the following line (112) in ValidatorCallout.js is producing the error:
var elementToValidate = this._elementToValidate = $get(elt.controltovalidate);

The problem is that the elt object has all of the expected properties prefixed with data-val- like so:
<span id="ctl00_Main_customVal" style="display: none;" data-val-evaluationfunction="CustomValidatorEvaluateIsValid" data-val="true" data-val-display="None" data-val-errormessage="A valid member number must be entered" data-val-controltovalidate="ctl00_Main_textboxStudent" data-val-isvalid="False"></span>

Changing the line to this seems to partially solve the issue:
var elementToValidate = this._elementToValidate = $get(elt.controltovalidate != null ? elt.controltovalidate : elt.getAttribute('data-val-controltovalidate'));

And the callout is shown to the user, but shows the wrong message and some events aren't properly handled. This is because the rest of the properties that define what the callout will be like are not being retrieved/used since they're all prefixed with data-val. For the moment I've been able to work around the issue with this hack in our code:

    $(function () {
        var calloutPrototype = Sys.Extended.UI.ValidatorCalloutBehavior.prototype;
        if (calloutPrototype != null) {
            calloutPrototype.get_element2 = calloutPrototype.get_element;
            calloutPrototype.get_element = function () {
                var elt = this.get_element2();
                var $valctrl = $(elt);
                elt.validateemptytext = $valctrl.data('val-validateemptytext');
                elt.clientvalidationfunction = eval($valctrl.data('val-clientvalidationfunction'));
                elt.evaluationfunction = eval($valctrl.data('val-evaluationfunction'));
                elt.val = $valctrl.data('val');
                elt.display = $valctrl.data('val-display');
                elt.errormessage = $valctrl.data('val-errormessage');
                elt.controltovalidate = $valctrl.data('val-controltovalidate');
                return elt;
            };
        }
    });
@MikhailTymchukDX
Copy link
Contributor

My attempt to reproduce this issue was unsuccessful. Would you please specify the following?

Would you please specify the following:

  1. A project's .NET Framework version.
  2. WebUIValidation.js script presence on a page.
  3. A version of the AJAX Control Toolkit used in a project.

@DavidIQ
Copy link
Author

DavidIQ commented Apr 1, 2016

I'm attaching this sample application that illustrates the problem.
TestWebApp.zip

@MikhailTymchukDX
Copy link
Contributor

This issue appears when the Web.config httpRuntime element targetFramework attribute is set to "4.5" value or above:

<configuration>
    <system.web>
        <httpRuntime targetFramework="4.5"/>
    </system.web>
</configuration>

This causes validators to be rendered with data- attributes rather than emitting code that assigns corresponding non-data attributes at runtime.

You can apply a simpler workaround by setting the Page.UnobtrusiveValidationMode to UnobtrusiveValidationMode.None, because UnobtrusiveValidationMode.WebForms is the defaul value for Page.UnobtrusiveValidationMode.

@DavidIQ
Copy link
Author

DavidIQ commented Apr 1, 2016

I see. Somehow in our application this is coming in as "None" which is why we had to assign "WebForms" in the init even though we're not setting this option in Web.config. Leaving it as "None" actually causes our validators to not do what they're supposed to do and the forms get submitted even though they shouldn't be.

@MikhailTymchukDX MikhailTymchukDX added this to the 16.2 milestone Apr 12, 2016
@DavidIQ
Copy link
Author

DavidIQ commented Apr 12, 2016

Great. Thanks for the fix. What does the release cycle look like for this project? Wondering when 16.2 will be available.

@MikhailTymchukDX
Copy link
Contributor

Based on the previous experience in CodePlex, it's about several months per release.

@MikhailTymchukDX MikhailTymchukDX changed the title ValidatorCalloutExtender fails with CustomValidator ValidatorCalloutExtender with CustomValidator causes an error if the httpRuntime setting is equal to 4.5 Aug 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants