0

I am looking for the best practice for validating a form.

I have worked with the asp.net validation controls in the past, but I cant say I'm too fond of them. I personally feel they complicate the aspx page itself and are not that flexible in terms of coloring or displaying certain notifications for the user. I like full control in case changes need to be made in the future.

I have worked with custom validation in the past. Wrote my own methods and returned the page with the appropriate error message/coloring if needed. But I'm not sure it was the best design. Should I write my methods in the page code file itself and acces the controls and the page directly, should I make a business object and give the values as parameters to a function and return errormessages?

I cant seem to find a good design for my validation.

What do you use? The asp.net controls? A custom way of validation? And if custom how do you implement it?

Thanks

4

1 回答 1

0

如果您真的在寻找灵活性,那么显然 MVC 就是答案。

但是,您的问题是关于 Web 表单的,我对验证控件没有任何问题。

使用CustomValidator是使控件更灵活的好方法。

我当然会把实际的验证逻辑放在你的域模型中。

您可以使用 CSS 更改错误文本的颜色,这是此类样式的正确位置。

于 2012-08-17T09:13:37.103 回答