使用 ASP.NET 验证控件创建自定义响应
我需要验证各种 ASP.NET 控件,但不是在验证失败时在每个控件旁边显示标准文本/星号/图像,而是需要显示自定义内容(更改输入文本框的轮廓颜色、显示工具提示等)。 )。在大多数情况下,我可以使用标准验证控件(例如,对于文本框使用RequiredFieldValidator),验证失败时的显示除外。
我已经开始创建 CustomValidators,但我需要为各种验证(必填字段、正则表达式、范围)多次执行此操作。仅重新创建这些验证器的逻辑以便它可以更改响应输出似乎是一种浪费。 MS 文档位于 http://msdn.microsoft.com/en-us/library /3w0bs977.aspx 表示在这种情况下,可以在客户端和服务器上完成自定义响应:“在客户端和服务器端,您都可以创建自定义响应,例如控件中的颜色更改或标签上文本的字体更改。”它给出了服务器端的示例,但没有给出客户端的方法。处理客户端自定义响应的最佳方法是什么?
I need to validate various ASP.NET controls, but instead of displaying the standard text/asterisk/image next to each when validation fails, I need to display custom content (change the outline color of the input textbox, display a tooltip, etc.). I could use a standard validation control in most cases (e.g., RequiredFieldValidator for a TextBox), except for the display when validation fails.
I've started out creating CustomValidators, but I need to do this many times for various validations (required field, regular expressions, ranges). It seems a waste to recreate the logic of these validators only so that it can change the response output. The MS documentation at http://msdn.microsoft.com/en-us/library/3w0bs977.aspx says a custom response can be done on both client and server in this case: "On both the client and server side you can create a custom response, such as a color change in a control or a font change for text on a label." It gives an example for the server side, but does not give a method for the client side. What is the best way to handle the custom response on the client?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
本文可能对您有帮助:
http://msdn.microsoft.com/en-us /library/aa479045.aspx
特别是此部分(查找“客户端验证”,然后在“特殊效果”下):
仍然有一些连接需要完成,您可以能够用一些 jQuery 之类的东西来整理
This article might help you:
http://msdn.microsoft.com/en-us/library/aa479045.aspx
Particularly this section (look for "Client Side Validation" then under there, "Special Effects"):
There is still some wiring up that needs to be done, which you may be able to tidy up with some jQuery or the like