Resetting ChangePassword control

If you try using the ChangePassword control for changing several passwords on the same page, you will notice that after confirming successful password change the control always shows the same success message and doesn’t offer any text entry fields any more. The reason is that the control maintains an internal state machine and doesn’t reset it properly after succes password changes. The state machine is controlled by internal property CurrentView that is not available for direct setting. But you can set it using reflection like this:

private void resetChangePasswordState(System.Web.UI.WebControls.ChangePassword cpControl)


System.Reflection.BindingFlags flags = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic |

System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static;

System.Type type = cpControl.GetType();

System.Reflection.PropertyInfo p = type.GetProperty(“CurrentView”, flags);

System.ComponentModel.TypeConverter converter = System.ComponentModel.TypeDescriptor.GetConverter(p.PropertyType);

object result = converter.ConvertFrom(“ChangePassword”); p.SetValue(cpControl, result, null);


4 thoughts on “Resetting ChangePassword control”

  1. Thanks buddy!!

    I was searching for this since morning, and finally got it… This hasn’t only solved my query, but also pushed me more to explore System.Reflection namespace into more depth.

    Fantastic man… i m really very thankful to u

    Nirman Doshi
    Sr. S/w developer

  2. Nice man thanks, just one more thing… when I tried to implement this, it didnĀ“t work, the passsword change control keeps in the same state if you dont “time it” right, in what I understood was a call to the function too early on the page life cycle, I needed to call it in the OnPreRender phase, with that little adjustement it worked just fine.

    psd. Sorry about my english.

Leave a Reply

Your email address will not be published. Required fields are marked *