Home > ASP.Net > Customizing the ChangePassword control

Customizing the ChangePassword control


try this example to Customizing the ChangePassword control and removing the required Current Password field

1) Remove the current password label/TextBox

2) Pass the new resetpassword to CurrentPassword Property which by the way is a getter only and not settable (SAD SAD)

Both of these things are not supported in this control. So let’s quickly fix requirement 1 and there are a couple of ways to fix this : 
a) You have to define a custom  <ChangePasswordTemplate>. This can be easily done by taking your ChangePassword control into DesignView in Visual studio, right click on the control and select “Convert to template”. You can then switch to HtmlView and set the visibility of CurrentPasswordLabel, CurrentPassword and CurrentPasswordRequired controls.
b) If you prefer to do this in code, then you can find the Label and TextBox for CurrentPassword and set its visiblity to false. Since a is a nobrainer, i’m including a sample code of method (b) :

Label l = (Label)changePassword1.ChangePasswordTemplateContainer.
if (l != null)
    l.Visible = false;

TextBox tb = (TextBox)changePassword1.ChangePasswordTemplateContainer.
if (tb != null)
    tb.Visible = false;

RequiredFieldValidator rfv = (RequiredFieldValidator)changePassword1.
if (rfv != null)
    rfv.Visible = false;

Now that we have the fields we want disabled, let’s head onto fix issue 2 :
We can’t pass the Autogenerated password to the CurrentPassword Property because its a getter only, however this getter returns the value from our CurrentPassword TextBox, and this job is done immidiately after ChangingPassword event fires. This is good news for us, so we can resolve issue 2 like this :

void changePassword1_ChangingPassword(object sender,
    LoginCancelEventArgs e)
    changePassword1.UserName = user.UserName;
        TextBox currentPassword = (TextBox)changePassword1.
        if (currentPassword != null)
            currentPassword.Text = user.ResetPassword();

Good Luck

Categories: ASP.Net Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: