Asp.Net End date greater than start date
Work on Asp.Net vs 08. Below is my code
<asp:TextBox ID="txtSTART_DATE" runat="server"></asp:TextBox>
<cc1:PopupControlExtender ID="txtSTART_DATE_PopupControlExtender" runat="server" CommitProperty=开发者_如何学编程"value"
CommitScript="e.value += '';" PopupControlID="pnlSTART_DATE"
Position="Bottom" TargetControlID="txtSTART_DATE">
</cc1:PopupControlExtender>
<asp:TextBox ID="txtEND_DATE" runat="server"
ontextchanged="txtEND_DATE_TextChanged"></asp:TextBox>
<cc1:PopupControlExtender ID="txtEND_DATE_PopupControlExtender" runat="server" CommitProperty="value"
CommitScript="e.value += '';" PopupControlID="pnlEND_DATE"
Position="Bottom" TargetControlID="txtEND_DATE">
</cc1:PopupControlExtender>
C# syntax is
protected void dtpSTART_DATE_SelectionChanged(object sender, EventArgs e)
{
AjaxControlToolkit.PopupControlExtender.GetProxyForCurrentPopup(this.Page).Commit(dtpSTART_DATE.SelectedDate.ToString("dd MMM yyyy"));//Set the value
}
protected void dtpEND_DATE_SelectionChanged(object sender, EventArgs e)
{
AjaxControlToolkit.PopupControlExtender.GetProxyForCurrentPopup(this.Page).Commit(dtpEND_DATE.SelectedDate.ToString("dd MMM yyyy"));//Set the value
}
want to compare start date with the end date.Verify that end date greater than start date and today date.How to check the value?
You could use the asp.net CompareValidator, e.g.
<asp:TextBox ID="txtSTART_DATE" runat="server" />
<asp:TextBox ID="txtEND_DATE" runat="server" />
<asp:CompareValidator ID="cmpDates" ControlToValidate="txtEND_DATE"
ControlToCompare="txtSTART_DATE" Operator="GreaterThan" Display="dynamic"
ErrorMessage="End date must be after start date" runat="server" />
This won't do a popup though, but if you are just after a validator then that should be ok.
The compare validator is actually very powerful, for instance, you can check the datatype of the argument as well, so I would use something like this:
<asp:TextBox ID="txtSTART_DATE" runat="server" />
<asp:CompareValidator ID="chkStartIsDate" runat="server" Display="Dynamic"
Operator="DataTypeCheck" Type="Date" ControlToValidate="txtSTART_DATE"
ErrorMessage="You must supply a valid start date" />
<asp:TextBox ID="txtEND_DATE" runat="server" />
<asp:CompareValidator ID="chkEndIsDate" runat="server" Display="Dynamic"
Operator="DataTypeCheck" Type="Date" ControlToValidate="txtEND_DATE"
ErrorMessage="You must supply a valid end date" />
<asp:CompareValidator ID="cmpStartAndEndDates" runat="server" Display="Dynamic"
Operator="GreaterThan" ControlToValidate="txtEND_DATE" ControlToCompare="txtSTART_DATE"
ErrorMessage="The end date must be after the start date" />
<asp:TextBox ID="txtStartDate" runat="server" />
<asp:TextBox ID="txtEndDate" runat="server" />
<asp:CompareValidator ID="cvStartEnd" Operator="GreaterThan" Type="Date"
ControlToValidate="txtEndDate" ControlToCompare="txtStartDate"
ErrorMessage="End date must be greater than start date!" runat="server"/>
Make sure to set property Type="Date"
otherwise it would do a string compare and give u wrong results.
精彩评论