简体   繁体   English

日期选择器的必填字段验证器

[英]Required field validator for date picker

i have a textbox which is filled with date from a datepicker(calendar is accessed by a link button) and a submit button. 我有一个文本框,其中填充有来自日期选择器的日期(可通过链接按钮访问日历)和提交按钮。 i created a required field validator for the textbox so that it is to be filled.The problem im facing is that the required field validator is not allowing me to click on the linkbutton(which makes me populate the textbox with a date)but instead it focuses on the textbox always.im stuck here plz help me . 我为文本框创建了一个必需的字段验证器,以便填充它。我面临的问题是,必需的字段验证器不允许我单击链接按钮(这使我用日期填充了文本框),而是我总是专注于文本框。我困在这里请帮助我。

You can use "validation groups". 您可以使用“验证组”。 On the controls property set the ValidationGroup to something like this. 在控件属性上,将ValidationGroup设置为如下所示。

TextBox.ValidationGroup = 1
Submit.ValidationGroup = 1
requiredFieldValidator.ValidationGroup = 1
LinkButton.ValidationGroup = 2

You need the LinkButton on a different ValidationGroup. 您需要在另一个ValidationGroup上使用LinkBut​​ton。 This can all be done in design. 这些都可以在设计中完成。

With this the validation will only affect what is on ValidationGroup 1. 这样,验证只会影响ValidationGroup 1上的内容。

Actually your solution is not good. 实际上,您的解决方案不好。
RequiredFieldValidator has some bugs (like that you mentioned). RequiredFieldValidator有一些错误(如您提到的)。
The best solution is implementing the validation by javascript yourself, and it's easy, flexible and practical 最好的解决方案是使用javascript自己实现验证,它简单,灵活且实用

I'm not clear how your linkbutton is displaying the calendar - client-side or server-side? 我不清楚您的linkbutton如何显示日历-客户端还是服务器端? - but you could try: -但您可以尝试:

  • setting RequiredFieldValidator.EnableClientScript to false . RequiredFieldValidator.EnableClientScript设置为false This will disable client-side validation by the RequiredFieldValidator. 这将禁用RequiredFieldValidator进行的客户端验证。 This will be enough if you're displaying the calendar using client-side script. 如果您要使用客户端脚本显示日历,这就足够了。

  • setting LinkButton.CausesValidation to false . LinkButton.CausesValidation设置为false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM