简体   繁体   中英

ASP.NET Membership controls reset password postback error

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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM