的RequiredFieldValidator不与jQuery UI的正确wrorking [英] RequiredFieldValidator is not wrorking properly with jquery UI
问题描述
我的工作 ASP.NET Web窗体
应用程序。我有一个pretty大单有很多领域,所以我想利用尽可能多的优势,尽可能从内置的服务器控件 Web窗体
。同时,由于表格太大我已经在逻辑上它separeted将使用三个部分的jQuery-UI-24年1月8日
和手风琴
菜单。我还用的DatePicker
此页面上的,所以我的页面看起来是这样的:
I am working on ASP.NET Web Forms
application. I have a pretty big form with a lot of fields so I want to take as much advantage as possible from the built-in server controls in Web Forms
. Also, because the form is too big I logically have separeted it into three parts using jquery-ui-1-8-24
and Accordion
menu. I also use DatePicker
on this page so my page looks like this:
<script>
$(function () {
$("#accordion").accordion();
$(".inpt-date").datepicker();
});
window.history.pushState('obj', '', 'myPage.aspx');
</script>
所以,它的正常工作,我已经implmeneted大量的逻辑在此页面上,一切都UTIL我说添加的那一刻做工精细的RequiredFieldValidator
例如:
<asp:TextBox ID="txtEnforcementCase" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator id="RequiredFieldValidator2"
ControlToValidate="txtEnforcementCase"
Display="Static"
Text="*"
ErrorMessage="This field is required!"
runat="server"/>
我觉得没有什么不寻常的,因为我使用的例子从 MSDN
和验证是pretty简单,所以我的标准实施为我工作。
I think nothing out of the ordinary since I'm using examples from msdn
and the validations are pretty simple so I the standard implementation works for me.
然而,当我添加的RequiredFieldValidator
我失去所有从的jQuery的UI
的造型和我得到这个错误在控制台:
However when I add the RequiredFieldValidator
I loose all the styling from the jquery-ui
and I get this error in the console :
Uncaught TypeError: undefined is not a function
我想发表评论,并取消对页面上的 JS
code。如果我只用:
I tried to comment and uncomment the JS
code on the page. If I use only :
window.history.pushState('obj', '', 'myPage.aspx');
一切都工作正常,但不管我同时使用 - 日期选取器和手风琴,或只是其中之一,我失去了朱埃里UI
造型和得到的错误指着在那里我有行 $(#手风琴),手风琴();
或 $(。INPT日期)日期选择器();
取决于哪一个是评论,哪些不是。我是pretty肯定有一些问题,当我尝试使用的jQuery的UI
和的RequiredFieldValidator
在一起。虽然寻找解决办法,我发现了一个局部的其中一项建议是只为日期选择器
这并不适合我,因为我用其他的jQuery的UI
方法,也是,如果我找到了 accorrdion
和日期选择器
以后的部分解决方案,我可能想用别的东西那么我将不得不找到该解决方法了,所以...有没有办法使用建设 - 以使客户端验证Windows窗体
与共同控制的jQuery的UI
?
everything's working fine, but no matter if I use both - the date picker and the accordion, or only one of them I loose the juery ui
styling and get the error pointing to the row where I have $("#accordion").accordion();
or $(".inpt-date").datepicker();
depending on which one is commented and which not. I'm pretty sure there's some problem when I try to use jquery-ui
and RequiredFieldValidator
together. While searching for solution I found a partial one which was just for the datepicker
which doesn't work for me because I use other jquery-ui
methods and also, if I find partial solutions for the accorrdion
and the datepicker
later on I may want to use something else then I'll have to find workaround for that too, so.. is there a way to make a client side validation in Windows Forms
using the build-in controls together with the jquery-ui
?
推荐答案
这需要先登记的的RequiredFieldValidator
从ASP.NET使用jQuery客户方(见<一href=\"http://stackoverflow.com/questions/16660900/webforms-unobtrusivevalidationmode-requires-a-scriptresourcemapping-for-jquery\">here).
The RequiredFieldValidator
from ASP.NET uses jQuery clientside which needs to be registered first (see here).
显然,ASP.NET注入了一个&LT;脚本&GT;
引用的jQuery在表格的第一部分
。
Apparently, ASP.NET injects a <script>
reference to jQuery in the first part of the form
.
如果您注册了自己的&LT;脚本&gt;将在
标记&LT; HEAD&GT;
您的网页(第一个的jQuery
然后的jQuery的UI
),这实际上意味着你失去你的 jquery- UI
绑定,因为的jQuery
是℃之后再次引用; HEAD&GT;
感谢的WebForms。
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.
解决方法是在参考脚本(的jQuery
,的jQuery的UI
和任何自定义脚本) 结束页面,例如表格后,
元素。
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.
希望这可以解决你的问题,至少它解决了我的。)
Hope this solves you problem, at least it solved mine :).
这篇关于的RequiredFieldValidator不与jQuery UI的正确wrorking的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!