jQuery UI的的DateTimePicker和ASP.NET CompareValidator为DataTypeCheck [英] jQuery UI datetimepicker and ASP.NET CompareValidator for DataTypeCheck
问题描述
我使用的jQuery UI的日期选择器一个ASP.NET文本框。文本框允许编辑,以便用户可以手动输入日期或清除现有条目。我添加了一个CompareValidator来执行对文本数据类型检查,并选择具有日期选择一个日期之后将产生错误。在ASP.NET客户端验证时出现错误:
微软JScript运行时错误:长度为空或不是对象
在ValidatorOnChange发生错误。我该如何解决这个问题?是否有可能与ASP.NET验证控件使用日期选择?
我的标记是:
< ASP:标签=服务器AssociatedControlID =uxInstallDate>安装日期< / ASP:标签>
< ASP:文本框ID =uxInstallDate=服务器栏=10/>
< ASP:CompareValidator =服务器的ControlToValidate =uxInstallDate操作员=DataTypeCheck类型=日期文本=*的ErrorMessage =安装日期必须是日期。显示=动态/>
请注意,在CompareValidator缺少的ID属性是故意的,增加不有所作为。我的jQuery初始化:
$(文件)。就绪(函数(){
$(#<%= uxInstallDate.ClientID%GT;)日期选择器({changeMonth:真});
});
我想我找到了解决办法。这是发生在IE,火狐没有(我没有测试任何其他浏览器)的错误。解决的办法是覆盖在初始化ONSELECT方式:
$(#<%= uxInstallDate.ClientID%GT;)日期选择器({changeMonth:真的,ONSELECT:功能(){}});
我找到了问题的描述和解决方案这里和一个替代的解决方案<一href=\"http://www.andrewrowland.com/article/display/ui-datepicker-dotnot-validator-problem\">here.
I'm using an ASP.NET textbox with the jQuery UI datepicker. The textbox allows edits so that the user can enter a date manually or clear an existing entry. I added a CompareValidator to perform a data type check on the textbox and this causes an error after selecting a date with the datepicker. The error occurs in the ASP.NET client side validation:
Microsoft JScript runtime error: 'length' is null or not an object
the error occurs in ValidatorOnChange. How can I fix this? Is it possible to use datepicker with the ASP.NET validator controls?
My markup is:
<asp:Label runat="server" AssociatedControlID="uxInstallDate">Install Date</asp:Label>
<asp:TextBox ID="uxInstallDate" runat="server" Columns="10" />
<asp:CompareValidator runat="server" ControlToValidate="uxInstallDate" Operator="DataTypeCheck" Type="Date" Text="*" ErrorMessage="Install Date must be a date." Display="Dynamic" />
Note that the missing ID attribute in the CompareValidator is intentional and adding it doesn't make a difference. My jQuery initialization is:
$(document).ready(function() {
$("#<%= uxInstallDate.ClientID %>").datepicker({ changeMonth: true });
});
I think I found a solution. This is a bug that occurs in IE, not Firefox (I didn't test any other browsers). The solution was to override the onSelect method in the initialization:
$("#<%= uxInstallDate.ClientID %>").datepicker({ changeMonth: true, onSelect: function() { } });
I found a description of the issue and the solution here and an alternate solution here.
这篇关于jQuery UI的的DateTimePicker和ASP.NET CompareValidator为DataTypeCheck的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!