简体   繁体   中英

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.

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

You need the LinkButton on a different ValidationGroup. This can all be done in design.

With this the validation will only affect what is on ValidationGroup 1.

Actually your solution is not good.
RequiredFieldValidator has some bugs (like that you mentioned).
The best solution is implementing the validation by javascript yourself, and it's easy, flexible and practical

I'm not clear how your linkbutton is displaying the calendar - client-side or server-side? - but you could try:

  • setting RequiredFieldValidator.EnableClientScript to false . This will disable client-side validation by the RequiredFieldValidator. This will be enough if you're displaying the calendar using client-side script.

  • setting LinkButton.CausesValidation to false .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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