比较验证器异常 [英] Compare validator exception

查看:62
本文介绍了比较验证器异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All,



我使用比较验证器来检查输入到文本框的日期格式。我收到以下错误。

Hello All,

I am using a compare validator to check the date format entered to a textbox. I am getting the following error.

<br />
Exception message: The base class includes the field ''cmpvStartDateFormat'', but its type (System.Web.UI.WebControls.CompareValidator) is not compatible with the type of control (System.Web.UI.WebControls.RegularExpressionValidator).





我的aspx页面代码如下:





My aspx page code are as follows:

<asp:TextBox name="dtStartDate" class="datefield" onclick="javascript:displayDatePicker(this.name, false,'mdy','/');"

                    ID="dtStartDate" Width="72px" MaxLength="10" runat="server" TabIndex="4"

                    onchange="datePickerClosed(this);"

                    />
                    <igr:HtmlClearValidator runat="server" ControlToValidate="dtStartDate"  Display="Dynamic"/>
                <img src="<%=calImagePath%>" width="18" height="18" align="absmiddle" class="hand"

                    border="0" onclick="javascript:displayDatePicker('dtStartDate', false,'mdy','/');">
                <asp:TextBox ID="txtStartTime" runat="server" Width="60px" MaxLength="5" TabIndex="6"></asp:TextBox>
                <igr:HtmlClearValidator runat="server" ControlToValidate="txtStartTime"  Display="Dynamic"/>
                <asp:RequiredFieldValidator ID="rfvStartDate" CssClass="err_txt" ControlToValidate="dtStartDate"

                    runat="server" EnableClientScript="true">*</asp:RequiredFieldValidator>
                <asp:CompareValidator runat="server" CssClass="err_txt" ID="cmpvStartDateFormat"

                    ControlToValidate="dtStartDate" Display="dynamic" Operator="DataTypeCheck" Type="Date"

                    EnableClientScript="true" dateorder="dmy">*</asp:CompareValidator>
                 <asp:CompareValidator ID="cmpvEventStartDate" EnableClientScript="false"  CssClass="err_txt" runat="server"

                ControlToValidate="dtStartDate"  Enabled="false"

                Operator="GreaterThanEqual">*</asp:CompareValidator>
                <asp:RequiredFieldValidator ID="rfvStartTime" CssClass="err_txt" runat="server" ControlToValidate="txtStartTime">*</asp:RequiredFieldValidator>
                <asp:RegularExpressionValidator ID="revStartTimeFormat" CssClass="err_txt" runat="server"

                    ControlToValidate="txtStartTime" ValidationExpression="^([01][0-9]|2[0-3]):[0-5][0-9]$">*</asp:RegularExpressionValidator>





有谁能帮我解决问题?



谢谢



Can anyone help me solving the problem?

Thanks

推荐答案

> * < ; / asp:RegularExpressionValidator >





有谁可以帮我解决问题?



谢谢



Can anyone help me solving the problem?

Thanks


嗨朋友们,



我得到了问题的解决方案。我在这里分享问题及其解决方案。



问题:

当我们输入日期时dd / mm / yyyy格式比较验证器无法获取它并且验证失败。这是因为验证器隐式地将日期格式设置为mm / dd / yyyy格式。



解决方案:



在页面加载时更改UICulture我们可以通过验证。



Hi friends,

I got the solution for the problem. I am sharing the problem and its solution here.

Problem:
When we are entering a date in dd/mm/yyyy format the compare validator couldn''t able to get it and validation gets failed. This is because the validator implicitly gets the date format as mm/dd/yyyy format.

Solution:

Changing the UICulture at page load we can able to pass the validation.

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");





上面的代码解决了我的问题。



谢谢



The above code solved my problem.

Thanks


这篇关于比较验证器异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆