开发者

RequiredFieldValidator and CustomValidator fire the same time?

I have a asp.net file with:

  • 3 radio boxes, one must be selected
  • a listbox in which a开发者_运维知识库 item must be selected
  • a captcha-validation

Now I have 4 Validators:

  • CustomValidator for the Radio boxes
  • CustomValidator for the Listbox
  • CustomValidator for the captcha-validation (which is saved in a session)
  • RequiredFieldValidator for the captcha-textbox not to be empty.

My problem is the order. If a user try to sent the formular and all 4 validators are wrong, only the RequiredFieldValidator will be shown, because the other 3 are serverside. The user now thinks "Oh, only one mistake" and corrected it. And after that, 3 other mistakes occour and the user might be a little angry about that - "Why the system doen't tell me in first playce?!"

So, how is there a user-nice solutiton?

Is there a way to fire the server-side-validation at the same time, a client-side validation fails? Or is there a way to fire the client-side validation on server side?

(Attention! I tried to remoce the RequiredFieldValidator and instead do a fourth CustomValidator. Wehn I do this, I have 4 CustomValidator and none Requ-Field-Val. It end up, that none CustomValidator will be hit, after the formular is send =( I don't know why.)


One of the way is to turn off client side validation for required field validator using EnableClientScript property. So that all your validations on the server side.

But better way (if possible) will be to use client side validations for all of them i.e. use custom js validation logic with your custom validators using ClientValidationFunction property - see this article for such example.


Add the ValidationGroup="abc" property for Controls validators and on Submit function Use Page.Validate("abc") method to have server-side controls validated at some Time.

Something like this.

Page.Validate("abc")
If Not Page.IsValid Then
    Return False  
End If
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜