ChangePassword控件和设置新的密码定期EX pression [英] ChangePassword control and setting regular expression for new password

查看:450
本文介绍了ChangePassword控件和设置新的密码定期EX pression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这看起来像它应该有一个简单的解决方案,但我似乎无法找到它。

This seems like it should have a simple solution but I can't seem to find it.

我使用ASP.NET 2.0应用程序的的ChangePassword 控制,同时使用 ChangePasswordTemplate SuccessTemplate 来定义自定义样式。该文本框的ID为如下:

I'm using the ChangePassword control in an ASP.NET 2.0 application, using both the ChangePasswordTemplate and SuccessTemplate to define custom styling. The textboxes have IDs as follows

        当前密码的文本框ID = CurrentPassword 结果
             新密码文本框ID = NEWPASSWORD 结果
确认新密码文本框ID = ConfirmPassword

        Current Password Textbox ID = CurrentPassword
             New Password Textbox ID = NewPassword
Confirm New Password Textbox ID = ConfirmPassword

有关 DRY 的原因,我想使用在自定义成员资格提供者定义,以验证新密码客户端的常规前pression。不幸的是,设置 ChangedPassword 控件的属性如下:

For DRY reasons, I want to use the regular expression that is defined in the Custom Membership Provider to validate the new password client side. Unfortunately, setting the ChangedPassword control's property as follows

ChangePassword.NewPasswordRegularExpression = 
    Membership.PasswordStrengthRegularExpression;
ChangePassword.NewPasswordRegularExpressionErrorMessage = 
    "Regex Error Message";

Page_Init 设置前pression预期值,但不会导致客户端验证对新密码发生(页面回和标准会员的ChangePassword 故障文本获取显示)。

in Page_Init sets the expression to the expected value, but does not cause client side validation to happen on the new password (the page posts back and the standard Membership ChangePassword failure text gets displayed).

我可以在 ChangePasswordTemplate 使用 RegularEx pressionValidator 并设置 ValidationEx pression 属性 Membership.PasswordStrengthRegularEx pression ,但是,我可以看到这样做的最佳途径,这需要通过控制递归在模板中找到 RegularEx pressionValidator 键,设置属性,这让我相信,一定有更优雅的方式。我在模板中的其他验证程序控件(必填字段,一个比较验证),在这种情况下,可能会导致与使用的ChangePassword 验证属性的冲突。

I could use a RegularExpressionValidator in the ChangePasswordTemplate and set the ValidationExpression property to Membership.PasswordStrengthRegularExpression but the best way that I can see to do this requires recursing through the controls in the template to find the RegularExpressionValidator and setting the property, which makes me believe that there must be a more elegant way. I have other validator controls in the template (required fields and a compare validator), in case this may be causing a conflict with using the ChangePassword validation properties.

我的问题是那么,是否使用模板,或执行的ChangePassword 控件的 NewPasswordRegularEx pression 物业工作的时候我需要下井 RegularEx pressionValidator 控制路线?

My question is then, does the ChangePassword control's NewPasswordRegularExpression property work when using templates or do I need to go down the RegularExpressionValidator control route?

编辑:

献上了一个赏金这个,因为我无法找到一个明确的答案,为什么的ChangePassword 控件的 NewPasswordRegularEx pression 属性不会验证客户端。

Offered up a bounty on this as I can't find a definitive answer as to why the ChangePassword control's NewPasswordRegularExpression property does not validate client side.

推荐答案

如果您使用转换为模板,不会自动创建RegularEx pressionValidator控制,因此不渲染到最后一页。这可以通过前查看页面的源代码,并转换为模板后得到证实。

If you use "Convert to Template", the RegularExpressionValidator control is not created automatically and therefore not rendered to the final page. This can be confirmed by viewing the page source before and after converting to template.

要添加RegularEx pressionValidator酷似一个ASP.NET使用没有模板的NEWPASSWORD TextBox和像这样的RequiredFieldValidator之间定义它:

To add a RegularExpressionValidator exactly like the one ASP.NET uses without the template, define it between the NewPassword TextBox and the RequiredFieldValidator like this:

<asp:TextBox ID="NewPassword" runat="server" TextMode="Password"></asp:TextBox>

<asp:RegularExpressionValidator ID="NewPasswordRegExp" runat="server"
    ErrorMessage="RegularExpressionValidator" Display="Dynamic"
    ControlToValidate="NewPassword" ValidationGroup="ChangePassword1"></asp:RegularExpressionValidator>

<asp:RequiredFieldValidator ID="NewPasswordRequired" runat="server" 
    ControlToValidate="NewPassword" ErrorMessage="New Password is required." 
    ToolTip="New Password is required." ValidationGroup="ChangePassword1">*</asp:RequiredFieldValidator>

您不能使用的ChangePassword的NewPasswordRegularEx pression酒店在这一点上改变常规的前pression。你必须要做到这一点,而不是:

You can't use the ChangePassword's NewPasswordRegularExpression property to change the regular expression at this point. You'll have to do this instead:

protected void Page_Init(object sender, EventArgs e)
{
    RegularExpressionValidator validator
        = ((RegularExpressionValidator)(ChangePassword1.Controls[0].FindControl("NewPasswordRegExp")));

    validator.ValidationExpression = Membership.PasswordStrengthRegularExpression;
    validator.ErrorMessage = "Regex Error Message";
}

我希望这有助于。

I hope this helps.

这篇关于ChangePassword控件和设置新的密码定期EX pression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆