ASP:RequiredFieldValidator 和 jQuery 不兼容
ASP:RequiredFieldValidator and jQuery incompatibility
我的页面(即选项卡)上有一些 jQuery 插件 运行。当我添加 <asp:requiredfieldvalidator>
时,jQuery 功能停止工作...有什么想法吗?
Uncaught TypeError: Cannot read property 'mobile' of undefined at
Object.initAnimation (zozo.tabs.js:1050) at ZozoTabs.init
(zozo.tabs.js:799) at HTMLDivElement. (zozo.tabs.js:2122)
at Function.each (jquery-2.1.4.js:374) at jQuery.fn.init.each
(jquery-2.1.4.js:139) at jQuery.fn.init.$.fn.zozoTabs
(zozo.tabs.js:2120) at HTMLDocument.
(PatientRegistration.js:18) at fire (jquery-2.1.4.js:3099) at
Object.fireWith [as resolveWith] (jquery-2.1.4.js:3211) at
Function.ready (jquery-2.1.4.js:3417)
if (jQuery.browser.mobile) {
//_base.settings.event = zozo.events.touchend;
_base.settings.shadows = false;
}
if ($.zozo.core.support.css.transition === false) {
_base.settings.animation.type = zozo.animation.types.jquery;
if (jQuery.browser.mobile) {
_base.settings.animation.duration = 0;
}
}
这已在 Stack Overflow 的其他地方得到回答:
Answer 1:
The RequiredFieldValidator
from ASP.NET uses jQuery clientside which
needs to be registered first (see here).
Apparently, ASP.NET injects a <script>
reference to jQuery in the
first part of the form.
If you registered your own <script>
tags inside of the <head>
of your
page (first jQuery then jQuery UI), this effectively means you're
losing your jQuery UI bindings because jQuery is referenced again
after the <head>
thanks to WebForms.
The solution is to reference your scripts (jQuery, jQuery UI, and any
custom scripts) at the end of the page, for example after the form
element.
Answer 2
You need a web.config key to enable the pre 4.5 validation mode.
More Info on ValidationSettings:UnobtrusiveValidationMode:
Specifies how ASP.NET globally enables the built-in validator controls
to use unobtrusive JavaScript for client-side validation logic.
Type: UnobtrusiveValidationMode
Default value: None
Remarks: If this key value is set to "None" [default], the ASP.NET
application will use the pre-4.5 behavior (JavaScript inline in the
pages) for client-side validation logic. If this key value is set to
"WebForms", ASP.NET uses HTML5 data-attributes and late bound
JavaScript from an added script reference for client-side validation
logic.
Example:
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings
我的页面(即选项卡)上有一些 jQuery 插件 运行。当我添加 <asp:requiredfieldvalidator>
时,jQuery 功能停止工作...有什么想法吗?
Uncaught TypeError: Cannot read property 'mobile' of undefined at Object.initAnimation (zozo.tabs.js:1050) at ZozoTabs.init (zozo.tabs.js:799) at HTMLDivElement. (zozo.tabs.js:2122) at Function.each (jquery-2.1.4.js:374) at jQuery.fn.init.each (jquery-2.1.4.js:139) at jQuery.fn.init.$.fn.zozoTabs (zozo.tabs.js:2120) at HTMLDocument. (PatientRegistration.js:18) at fire (jquery-2.1.4.js:3099) at Object.fireWith [as resolveWith] (jquery-2.1.4.js:3211) at Function.ready (jquery-2.1.4.js:3417)
if (jQuery.browser.mobile) {
//_base.settings.event = zozo.events.touchend;
_base.settings.shadows = false;
}
if ($.zozo.core.support.css.transition === false) {
_base.settings.animation.type = zozo.animation.types.jquery;
if (jQuery.browser.mobile) {
_base.settings.animation.duration = 0;
}
}
这已在 Stack Overflow 的其他地方得到回答:
Answer 1:
The
RequiredFieldValidator
from ASP.NET uses jQuery clientside which needs to be registered first (see here).Apparently, ASP.NET injects a
<script>
reference to jQuery in the first part of the form.If you registered your own
<script>
tags inside of the<head>
of your page (first jQuery then jQuery UI), this effectively means you're losing your jQuery UI bindings because jQuery is referenced again after the<head>
thanks to WebForms.The solution is to reference your scripts (jQuery, jQuery UI, and any custom scripts) at the end of the page, for example after the form element.
Answer 2
You need a web.config key to enable the pre 4.5 validation mode.
More Info on ValidationSettings:UnobtrusiveValidationMode:
Specifies how ASP.NET globally enables the built-in validator controls to use unobtrusive JavaScript for client-side validation logic.
Type: UnobtrusiveValidationMode
Default value: None
Remarks: If this key value is set to "None" [default], the ASP.NET application will use the pre-4.5 behavior (JavaScript inline in the pages) for client-side validation logic. If this key value is set to "WebForms", ASP.NET uses HTML5 data-attributes and late bound JavaScript from an added script reference for client-side validation logic.
Example:
<appSettings> <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" /> </appSettings