asp文本框控件上必需的字段验证和当前日期验证 [英] Required Field Validation and Current Date Validation on asp textbox Control
本文介绍了asp文本框控件上必需的字段验证和当前日期验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个控件,如:
I have a control like:
<asp:TextBox ID="_txtLeadDate" runat="server"></asp:TextBox>
<AjaxControl:CalendarExtender ID="_txtLeadDate_CalendarExtender" Format="dd/MMM/yyyy" runat="server" Enabled="True" TargetControlID="_txtLeadDate"></AjaxControl:CalendarExtender><br />
<asp:RequiredFieldValidator ID="RequirePreDate" runat="server" ControlToValidate="_txtLeadDate" ErrorMessage="Please select a Date" ForeColor="Red" Font-Size="10px" SetFocusOnError="True"></asp:RequiredFieldValidator>
现在我正在尝试添加另一个验证,选择的日期不应该是过去的日期(仅当前和未来的日期)。我怎样才能做到这一点。请帮助。
Now I am trying to add another validation that date selected should't be a past date (only current and future date). How can I achieve that. Kindly help.
推荐答案
您可以简单地将开始日期设置为昨天,然后用户无法选择旧时代。在页面加载中执行如下
you can simply set start date as yesterday then user can't select old days. in page load do as below
protected void Page_Load(object sender, EventArgs e)
{
_txtLeadDate_CalendarExtender.StartDate = DateTime.Now.AddDays(-1); //to dissable past Date
}
这篇关于asp文本框控件上必需的字段验证和当前日期验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文