自动标记具有RequiredFieldValidator的ASP.Net控件
是否有一种干净且集中的方式来自动为 ASP.Net 控件(即文本框)指定背景颜色或其他 CSS 属性,并启用RequiredFieldValidator?
目前我已手动将所需控件的背景颜色设置为黄色。 我想用一个中心方法替换它,这样如果客户端请求不同的颜色或标记,或者字段的状态从必需更改为不需要,反之亦然,我不会错过任何控件。
谢谢
更新
该网站是预编译的。 是否可以在编译时将 Css 类或其他符合标准的标志附加到 ControlToValidtate 属性中的项目?
Is there a clean and centralized way to automatically designate a background color or other CSS property for ASP.Net controls (i.e. a TextBox) with an enabled RequiredFieldValidator?
Currently I have manually set the background color of required controls to yellow. I would like to replace that with a central method so if the client requests a different color or marker or if a field's status changes from required to not or vice versa, I won't miss any of the controls.
Thanks
Update
This site is pre-compiled. Can something append a Css Class or other standards-compliant flag to items in the ControlToValidtate property at compile time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不添加一个 required 的 css 类呢? 您可以在单个控件上通过空格分隔多个类,因此想象一个带有数字的输入字段:
现在我可以有两个类,一个类右对齐文本,另一个类处理所需的字段要求。
在页面渲染之前编辑
一个选项,遍历页面中的每个控件,如果是必填字段验证器,则找到其对应的控件并设置 css 属性; 然而,对于您可以在设计时处理的事情来说,这是一项大量的工作。
Why not add a css class of required. You can have multiple classes on a single control by space delimiting them so imagine an input field which takes a number:
Now I can have two classes one which right aligns the text and one which handles the required field requirements.
Edit
One option before the page is rendered to walk through each control in the page, and if it's a required field validator, then find it's corresponding control and set the css property; however, this is a lot of work for somethign which you can tackle at design time.