Click here to Skip to main content
11,636,598 members (71,784 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: 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(, false,'mdy','/');"
                    ID="dtStartDate" Width="72px" MaxLength="10" runat="server" TabIndex="4"
                    <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"
                <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?

Posted 17-Jan-13 21:03pm
Rai Pawan at 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
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.

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.


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.


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

  Print Answers RSS
0 295
1 Sergey Alexandrovich Kryukov 275
2 OriginalGriff 233
3 Suvendu Shekhar Giri 225
4 stibee 215
0 OriginalGriff 8,941
1 Sergey Alexandrovich Kryukov 8,459
2 Mika Wendelius 6,849
3 F-ES Sitecore 2,364
4 Suvendu Shekhar Giri 2,320

Advertise | Privacy | Mobile
Web01 | 2.8.150728.1 | Last Updated 18 Jan 2013
Copyright © CodeProject, 1999-2015
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