开发者

ASP.NET Validation Patterns

开发者 https://www.devze.com 2023-02-04 06:58 出处:网络
I\'m use开发者_运维技巧d to creating one large validation function for my methods. In ASP.NET, I can use custom validators and OnServerValidate which is more OO but also tightly binds the logic to the

I'm use开发者_运维技巧d to creating one large validation function for my methods. In ASP.NET, I can use custom validators and OnServerValidate which is more OO but also tightly binds the logic to the markup and makes me a little uneasy that the validators might one day get removed inadvertently.

What patterns do you recommend AND is there a way that I can use both patterns? Perhaps creating a large block to call all custom validators. The downside to this is that the methods may get called twice. But, at least, it ensures the validation.

Appreciate any thoughts.


One tip I've found very useful is to make sure that you set the ValidationGroup property on every validator you create and the controls that will trigger the form submission. Then you won't be left scratching your head as to why something isn't working due to an unrelated validator in some user control.


There's a lot of good thinking on this question the Validation block from MS. For the other end of the spectrum, look at JQuery validation. What the validation block does in a kind of heavy, backend way, the JQuery validation does in a lightweight, declarative format. This does have the risk of removal that you're talking about.

0

精彩评论

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