【问题标题】:Validate end date should be greater than start date?验证结束日期应该大于开始日期?
【发布时间】:2015-02-25 12:33:52
【问题描述】:

datePicker.ascx
<asp:TextBox ID="txtDatePicker" runat="server"></asp:TextBox> 
    <asp:ImageButton runat="Server" ID="Image1" ImageUrl="~/Images/calendar.png" AlternateText="Click to show calendar" /> 
    <ajaxToolkit:CalendarExtender Format="dd/MM/yyyy" ID="CalendarExtender1" TargetControlID="txtDatePicker" runat="server" PopupButtonID="Image1" />

register.aspx
<%@ Register Src="~/Modules/datePicker.ascx" TagName ="datePicker" TagPrefix ="uc1"  %>

Start Date   <uc1:datePicker ID="datePickerSD" runat="server" >
End Date     <uc1:datePicker ID="datePickerED" runat="server" />
 <asp:CustomValidator  ID="CustomValidator1"  ControlToValidate="datePickerED"
                      ErrorMessage="End date should be greater than start date" runat="server" />

试图获取开始日期的clientid..但很困惑..

【问题讨论】:

    标签: asp.net


    【解决方案1】:
    <asp:CompareValidator ID="cmpr" runat="server" ControlToCompare ="txtDate1" ControlToValidate="txtDate2" Operator="GreaterThan" Type="Date" ErrorMessage="To date should great than small data"></asp:CompareValidator>
    

    你试过比较验证器吗?这可以帮助你

    【讨论】:

    • 请看上面的代码,我用的是ajax calendarextender..如何在ControlToCompare属性中获取datePickerSD的clientid?
    • 那你得用jquery或者JavaScript比较一下
    • 我尝试使用 javascript 和 jquery。但我可以传递数据选择器的值。请参阅上面的代码,我添加了 customvalidator 并调用了 javascript
    【解决方案2】:

    已解决:

    <asp:CompareValidator ID="compareValidatorDate" runat="server" ControlToValidate="datePickerED$txtDatePicker" ControlToCompare ="datePickerSD$txtDatePicker" CultureInvariantValues="true" 
                                                ErrorMessage="End date should be greater than start date" Operator="GreaterThanEqual" SetFocusOnError="false" Type="String" Display="Dynamic" EnableClientScript="true" Font-Size="Small" ForeColor="Red"></asp:CompareValidator>

    【讨论】:

      猜你喜欢
      • 2012-08-31
      • 1970-01-01
      • 1970-01-01
      • 2011-12-05
      • 1970-01-01
      • 2018-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多