I have two TextBox
controls for start date & end date input. I have to validate that end date is not greater than start date & the difference between start date & end date is not more than 12 months.
相关问题
- Carriage Return (ASCII chr 13) is missing from tex
- How to store image outside of the website's ro
- 'System.Threading.ThreadAbortException' in
- Request.PathInfo issues and XSS attacks
- How to dynamically load partial view Via jquery aj
相关文章
- asp.net HiddenField控件扩展问题
- asp.net HiddenField控件扩展问题
- Asp.Net网站无法写入错误日志,测试站点可以,正是站点不行
- asp.net mvc 重定向到vue hash字符串丢失
- FormsAuthenticationTicket expires too soon
- “Dynamic operations can only be performed in homog
- What is the best way to create a lock from a web a
- Add to htmlAttributes for custom ActionLink helper
Quick and easy: Two validators, one a Comparison Validator (which compares both controls), and a Custom Validator with a server-side method to check the end date.
Also you can use Timespan:
You will have to use a
CustomValidator
to do this. In your markyou, you will have something like this:And in your code behind, you define the validation handler:
Note that the code above is prone to throw exceptions. You will need to add additional validators to check that the dates entered can be parsed, and the
ValidateDuration
method should be modified to confirm that these other validators have passed before doing its own tests.Further, you might want to yet add another validator to test that the end date is in fact greater (or equal to) the start date. Breaking this rule should probably raise its own validation error message.
And why you're not about that