ASP.NET 会员控件重置密码回发错误

发布于 2024-10-21 07:44:30 字数 2350 浏览 2 评论 0原文

我编写了一个简单的 jQuery 对话框,如果登录用户在过去 90 天内没有重置密码,该对话框将显示在 asp 面板中。这很好用,但是当用户输入密码并按提交将新密码插入数据库时​​,父页面会在用户控件上触发单击事件之前回发。

它的设置方式如下:

default.aspx

 <asp:Panel ID="pnlTest" runat="server" Visible="false">
    <div id="dialog" title="Password must be reset">
        <cms:ResetPassword runat="server" ID="reset" />
    </div>
 </asp:Panel>

ResetPassword.ascx:

<div style="overflow:auto; white-space:nowrap;">
    <table class="tableChangePassword">
        <tr>
            <td>Current Password</td>
            <td colspan="2"><asp:TextBox runat="server" ID="txtCurrentPass" TextMode="Password" /></td>
        </tr>
        <tr>
            <td>New Password</td>
            <td><asp:TextBox runat="server" ID="txtNewPass1" TextMode="Password" CssClass="newPass1" /></td>
        </tr>
        <tr>
            <td>Verify New Password</td>
            <td><asp:TextBox runat="server" ID="txtNewPass2" TextMode="Password" CssClass="newPass2" /></td>
        </tr>
        <tr>
            <td colspan="2">
            </td>
        </tr>
        <tr>
            <td colspan="3"><asp:LinkButton runat="server" ID="lbUpdatePass" Text="Submit" onclick="lbUpdatePass_Click" /></td>
        </tr>
    </table>    
    <asp:Label runat="server" ID="lblMSG" />
</div>

ResetPassword代码隐藏:

public partial class ResetPassword : UserControl
{
    protected void lbUpdatePass_Click(object sender, EventArgs e)
    {
        string newPass = txtNewPass1.Text;
        string confirmNewPass = txtNewPass2.Text;
        if (newPass == confirmNewPass)
        {
            MembershipUser user = AuthenticatedUser.GetMembershipProvider().GetUser(AuthenticatedUser.LoginUserID, false);
            if (user != null)
            {
                string resetPsw = user.ResetPassword();
                user.ChangePassword(resetPsw, newPass);
                lblMSG.Text = "Password Changed Successfully";
            }
        }
    }
}

每当我单击按钮更改密码时,默认页面都会调用回发,并且会清空输入的用于更改密码的文本,因此,当调用 click 函数时,字符串会显示为“”并引发错误。

I have written a simple jQuery dialog box that will appear in an asp panel if the logged in user has not reset their password in the last 90 days. This is working great, however when the user types in their password and presses submit to insert the new password into the database, the parent page is posting back before the click event is fired on the user control.

Here is how it is set up:

default.aspx

 <asp:Panel ID="pnlTest" runat="server" Visible="false">
    <div id="dialog" title="Password must be reset">
        <cms:ResetPassword runat="server" ID="reset" />
    </div>
 </asp:Panel>

ResetPassword.ascx:

<div style="overflow:auto; white-space:nowrap;">
    <table class="tableChangePassword">
        <tr>
            <td>Current Password</td>
            <td colspan="2"><asp:TextBox runat="server" ID="txtCurrentPass" TextMode="Password" /></td>
        </tr>
        <tr>
            <td>New Password</td>
            <td><asp:TextBox runat="server" ID="txtNewPass1" TextMode="Password" CssClass="newPass1" /></td>
        </tr>
        <tr>
            <td>Verify New Password</td>
            <td><asp:TextBox runat="server" ID="txtNewPass2" TextMode="Password" CssClass="newPass2" /></td>
        </tr>
        <tr>
            <td colspan="2">
            </td>
        </tr>
        <tr>
            <td colspan="3"><asp:LinkButton runat="server" ID="lbUpdatePass" Text="Submit" onclick="lbUpdatePass_Click" /></td>
        </tr>
    </table>    
    <asp:Label runat="server" ID="lblMSG" />
</div>

ResetPassword Codebehind:

public partial class ResetPassword : UserControl
{
    protected void lbUpdatePass_Click(object sender, EventArgs e)
    {
        string newPass = txtNewPass1.Text;
        string confirmNewPass = txtNewPass2.Text;
        if (newPass == confirmNewPass)
        {
            MembershipUser user = AuthenticatedUser.GetMembershipProvider().GetUser(AuthenticatedUser.LoginUserID, false);
            if (user != null)
            {
                string resetPsw = user.ResetPassword();
                user.ChangePassword(resetPsw, newPass);
                lblMSG.Text = "Password Changed Successfully";
            }
        }
    }
}

Whenever I click the button to change the password, the default page is calling a postback and it is blanking out the text that was input to change the password, so when the click function gets called the strings come through as "" and it throws an error.

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

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

发布评论

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

评论(1

最笨的告白 2024-10-28 07:44:30

我在测试项目中实现了上面的内容,并且它工作正常。 lbUpdatePass_Click 事件在文本框的每个文本属性中具有正确的值。您的父级或子级 Page_Load 事件中是否有操作这些文本字段的代码?您上面未显示的任何其他代码吗?

I implemented what you have above in a test project, and it worked correctly. The lbUpdatePass_Click event had the correct values in each text property of the text boxes. Do you have code in the parent or child Page_Load events that are manipulating those text fields at all? Any other code that you are not displaying above?

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