您可以将 asp:customvalidator 与 asp:ChangePassword 控件一起使用吗?

发布于 2024-07-22 12:52:54 字数 201 浏览 5 评论 0 原文

我正在寻找有关如何对 asp:ChangePassword 控件使用自定义验证控件的想法。 尝试在 asp:CustomValidator 控件上设置“ControlToValidate”属性会导致:

无法验证“passwordValidation”的 ControlToValidate 属性引用的控件“changePassword1”。

谢谢。

I'm looking for ideas on how to use a custom validation control for an asp:ChangePassword control. A simple attempt to set the "ControlToValidate" property on the asp:CustomValidator control results in:

Control 'changePassword1' referenced by the ControlToValidate property of 'passwordValidation' cannot be validated.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

苦笑流年记忆 2024-07-29 12:52:54

导致此错误消息的根本问题是 ChangePassword 控件没有在类级别设置“ValidationProperty”属性。 如前所述,您可以从 CustomValidator 中省略 ControlToValidate 属性。 这可能是 ChangePassword 控件的最佳计划。

如果您尝试将 CustomValidator 与自定义控件一起使用,请在自定义控件的类上设置 ValidationProperty:

[DefaultProperty("StateName"), ValidationProperty("StateName")]
public class StateBox: CompositeControl
{
    ...

如果要将 CustomValidator 与未设置 ValidationProperty 属性的库控件一起使用,请从库控件派生一个类并设置派生类上的 ValidationProperty。

The fundamental problem that leads to this error message is that the ChangePassword control doesn't have a "ValidationProperty" attribute set at the class level. As mentioned earlier, you can just leave out the ControlToValidate attribute from your CustomValidator. This is probably the best plan for the ChangePassword control.

If you are trying to use CustomValidator with a custom control, set the ValidationProperty on your custom control's class:

[DefaultProperty("StateName"), ValidationProperty("StateName")]
public class StateBox: CompositeControl
{
    ...

If you want to use CustomValidator with a library control that doesn't have the ValidationProperty attribute set, derive a class from the library control and set the ValidationProperty on your derived class.

遮了一弯 2024-07-29 12:52:54

如果您使用 javascript 直接获取控件,则可以使用 CustomValidator 验证任何内容。 无法设置 ControlToValidate 意味着您无法获取 EventArgs 中的数据,必须自己获取。

You can validate anything with CustomValidator if you use javascript to get the controls directly. Not being able to set ControlToValidate means that you don't get the data in the EventArgs and have to get it yourself.

那小子欠揍 2024-07-29 12:52:54

您需要将 ChangePassword 控件更改为模板化控件才能使用自定义验证器。 请务必将自定义验证器的验证组设置为与模板中的其他控件相同。 或者,ChangePassword 控件有一个 NewPasswordRegularExpression 属性,可以满足您的需求。

You need to change the ChangePassword control to be a templated control in order to use a custom validator. Be sure to set the custom validator's validation group to be the same as the other controls in the template. Alternatively, the ChangePassword control has a NewPasswordRegularExpression property that may meet your needs.

橙味迷妹 2024-07-29 12:52:54

是的,只需使用模板:

http://quickstarts.asp.net/QuickStartv20/util/srcview.aspx?path=~/aspnet/samples/ctrlref/login/ChangePasswordTemplates.src

http://quickstarts.asp.net/quickstartv20/aspnet/doc/ctrlref/login/changepassword.aspx

只要 textbox-id 是“用户名”(或任何您想要验证的内容),您就可以向模板添加任何类型的验证器。

Yes, just use templates:

http://quickstarts.asp.net/QuickStartv20/util/srcview.aspx?path=~/aspnet/samples/ctrlref/login/ChangePasswordTemplates.src

http://quickstarts.asp.net/quickstartv20/aspnet/doc/ctrlref/login/changepassword.aspx

As long as the textbox-id is "Username" (or whatever you want to validate), you can add any kind of validator to the template.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文