使用comparevalidator用户输入日期应大于或等于今天的日期 [英] using comparevalidator user input date should be more than or equal to todays date

查看:91
本文介绍了使用comparevalidator用户输入日期应大于或等于今天的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户将使用文本框或日历输入日期.....

任何想法如何使用比较验证器...?

user will input date using textbox or calender.....
any ideas how to do it with compare validator...?

推荐答案

您可以使用comparevalidator,如下所示



You can use comparevalidator as below

<asp:CompareValidator id="cvCompareDate" 



runat="server" ControlToValidate="txtBox"

ErrorMessage="DateError" Operator="GreaterThanEqual"

Type="Date"></asp:CompareValidator>





在page_load事件中,您可以设置ValueToCompare



In the page_load event you can set the ValueToCompare

cvCompareDate.ValueToCompare = DateTime.Now.ToString("MM/dd/yyyy")

//如果您使用的是global / localiza,则相应地更改日期格式可能有不同格式的



希望这有帮助

//change accordingly the date format if you are using globalization/localization which may have different format

Hope this helps


嗨...

看到这个一,可能对你有用。

这里使用TextBox1,TextBox2和1Label。

Hi...
See this one,may its useful to u.
Here am using TextBox1,TextBox2 and 1Label.
string from = TextBox1.Text;
DateTime dfrom=DateTime.ParseExact(from,"M/d/yyyy",CultureInfo.InvariantCulture);
string to = TextBox2.Text;
DateTime dto = DateTime.ParseExact(to, "M/d/yyyy", CultureInfo.InvariantCulture);
            if (dto < dfrom)
            {
                lblsetting.ForeColor = Color.Red;
                lblsetting.Text = "Pls Enter Valid Date in ToDate";
                txtvalidityto.Focus();
            }



谢谢你。


Thank u.


http://stackoverflow.com/questions/2264215/using -the-comparevalidator-control-to-compare-user-input-date-with-todays-date [ ^ ]


这篇关于使用comparevalidator用户输入日期应大于或等于今天的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆