将RequiredValidator附加到呈现文本框的自定义服务器控件上
我不知道这是否真的可能,但我正在尽力。
如果我有一个(复杂的)自定义服务器控件,它(除了其他控件之外)在 UI 上呈现一个文本框。 将服务器控件放置在页面上时,是否可以将 requiredField 验证器附加到该服务器控件,以便验证器验证该控件的 Text 属性,该属性指向所呈现的 TextBox 的 Text 属性?
当然,我可以将RequiredField 验证器直接合并到服务器控件中,但由于其他原因这是不可能的(我们在UI 上自动呈现RequiredField 验证器)。
感谢您的帮助。
I don't know whether this is really possible, but I'm trying my best.
If I have a (complex) custom server control which (beside other controls) renders a TextBox on the UI. When placing the server control on a page, would it be possible to attach a RequiredField validator to that server control, such that the validator validates the Text property of that control which points to the Text property of the rendered TextBox?
Of course I could incorporate the RequiredField validator directly into the server control, but this is for other reasons not possible (we are rendering RequiredField validators automatically on the UI).
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为一种解决方案是将 TextBox 控件放入面板中,然后在 Page_Load 事件处理程序上动态添加RequiredValidator 控件。
然后
我将 CustomTextBox 放入面板中,以确保添加时验证控件位置正确
I think one solution is to put your TextBox control inside a Panel then you add the RequiredValidator control dynamically on the Page_Load event handler.
then
I put the CustomTextBox inside the panel to assure that the validation controle place is correct when added
我明白了,这是我第二次回答我自己的帖子:)下次我会做更深入的研究。
对于那些可能遇到同样问题的人。 您必须在服务器控件的类上指定
ValidationProperty
属性。 例如,如果您的服务器控件公开了一个属性“Text”,该属性向用户显示并且也应该进行验证,您可以添加以下内容:然后它应该可以工作。
I got it, the 2nd time that I'm answering to my own post :) Next time I'll do a deeper research before.
For those of you that may encounter the same problem. You have to specify the
ValidationProperty
attribute on your server control's class. For instance if your server control exposes a property "Text" which is displayed to the user and which should also be validated, you add the following:Then it should work.