Click here to Skip to main content
12,243,173 members (22,245 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# C#4.0
Hello All,

I am using a compare validator to check the date format entered to a textbox. I am getting the following error.
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).

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
Posted 17-Jan-13 22:03pm
v2
Comments
Rai Pawan 18-Jan-13 3:14am
   
Can you check whether you are getting this exception on the code behind of the aspx page? If so at what line?
- Pawan

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 18 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100