2012-01-03 92 views
0

在我的web應用程序中,我編寫比較驗證器來比較兩個日期[From and date],但它顯示錯誤。我的比較驗證器是這樣的。從日期到日期驗證?

<asp:CompareValidator ID="CompareValidator1" runat="server" Text="*" Display="None" ValidationGroup ="a" ControlToValidate="txtTo" ValueToCompare="txtFrom" Operator="GreaterThan" Type ="Date" 
        ErrorMessage="Date Should Greater Than From Date"></asp:CompareValidator> 

回答

2

您應該使用「ControlToCompare」屬性而不是「ValueToCompare」屬性。

像下面

<asp:CompareValidator ID="CompareValidator1" runat="server" Text="*" Display="None" ValidationGroup ="a" ControlToValidate="txtTo" ControlToCompare="txtFrom" Operator="GreaterThan" Type ="Date" 
       ErrorMessage="Date Should Greater Than From Date"></asp:CompareValidator> 
+0

嗨Reshma謝謝yaar,它工作正常,我真的忘記了財產controltocompare。 @ suryasasidhar13 @ gmail.com – 2012-01-03 06:32:26

+0

現在它不是正確的驗證,例如當我選擇'1/1/2012'和迄今'25/1/2012'它給予消息日期應該大於形式日期@reshma – 2012-01-03 12:28:26

+0

@suryasasidhar你應該嘗試這個ControlToCompare =「txtTo」和ControlToValidate =「txtFrom」 – 2012-01-04 09:47:31