我为用户创建文本框以选择日期并设置 requiredfieldvalidator。
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="StartDate" ErrorMessage="RequiredFieldValidator"
ValidationGroup="Search" SetFocusOnError="True" Display="Dynamic"
ToolTip="*Fill START Date!">*Fill START Date!</asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="EndDate" ErrorMessage="RequiredFieldValidator"
ValidationGroup="Search" Display="Dynamic" ToolTip="*Fill END Date!">*Fill END Date!</asp:RequiredFieldValidator>
<asp:Label ID="DateFilter" runat="server"
Text="Filter by Date from :" style="font-family: 'Arial Narrow'"
AssociatedControlID="StartDate"></asp:Label>
<asp:TextBox ID="StartDate" runat="server" ></asp:TextBox>
<a href="javascript:;" onclick="window.open('CalendarPopup.aspx?textbox=StartDate','cal','width=220,height=205,left=270,top=180')"><img id="Img1"
src="calendar-icon.gif" border="0" runat="server" alt="calendar"
style="height: 23px" align="bottom"></a>
<asp:Label ID="Label4" runat="server" Text="to" Font-Names="Arial Narrow"
AssociatedControlID="EndDate"></asp:Label>
<asp:TextBox ID="EndDate" runat="server"></asp:TextBox>
<a href="javascript:;" onclick="window.open('CalendarPopup.aspx?textbox=EndDate','cal','width=220,height=205,left=270,top=180')"><img id="Img2"
src="calendar-icon.gif" border="0" runat="server" alt="calendar"
style="height: 23px" dir="ltr"></a>
<asp:Button
ID="Search" runat="server" BackColor="Black" Font-Names="Arial Narrow"
ForeColor="White" Text="SEARCH" Width="73px" onclick="Search_Click" />
然后,我需要使用比较验证器比较第一个日期必须小于第二个日期。
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="EndDate" ControlToValidate="StartDate"
ErrorMessage="CompareValidator" Operator="GreaterThanEqual" Type="Date"
ValidationGroup="Search" Display="Dynamic" SetFocusOnError="True">*First date must be less than or equal to Second
date!</asp:CompareValidator>
两个验证器都不起作用。任何人请帮忙。谢谢..:) 西蒂