Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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).


My aspx page code are as follows:

XML
<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
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
[no name] 18-Jan-13 3:18am    
There is nothing to do with the code behind as nothing is set there in the code behind for the date field / validator.

1 solution

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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900