如何以编程方式将 ASCX 内的 ASP.NET 控件添加到外部RequiredFieldValidator?
我在用户控件 (ASCX) 中有一个下拉列表,我想从放置 ASCX 的页面进行验证,但是当我将 ControlToValidate 设置为下拉列表时,页面抱怨说它不能找不到。 感谢您的任何帮助/建议。
I have a drop-down list inside a user control (ASCX) that I want to validate from the page on which I've placed the ASCX, but when I set the ControlToValidate to the drop-down list the page complains that it can't be found. Thanks for any help/suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用用户控件中的公共属性公开下拉列表:
然后使用公开的下拉列表的 UniqueID 将控件设置为在您放置用户控件的页面的页面加载中进行验证:
Expose the dropdown list with a public property in your user control:
Then use the UniqueID of the exposed Dropdown to set the control to validate in the page load of the page on which you dropped the user control:
我知道执行此操作的唯一方法是在您的用户控件类中执行此操作:
然后在您放置用户控件的页面中:
不完全一样,但这是我唯一的解决方法知道。
The only way I know to do this is to do this in your user control class:
And then in the page you place the user control on:
Not quite the same thing, but that's the only workaround that I know.
我认为验证用户控件的最佳方法是在用户控件中使用公共方法:
其中
reqRecipientName
、reqRecipientMail
... 是验证器的 ID(它们也是 insice ascx) )。然后在Page里面的submit方法中调用
controlId.Validate();
这对我有用。
I think the best way to validate user control is to have public method inside your user control:
where
reqRecipientName
,reqRecipientMail
... are ID of validators (they are also insice ascx).And then on Page inside submit method call
controlId.Validate();
This works for me.