Usable Asp.Net

Little things that make Asp.Net more usable

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);

}

Posted: Oct 30 2007, 05:32 AM by egoldin | with 3 comment(s)
Filed under:

Comments

Thomas said:

thanks man! you saved my day!

# March 2, 2008 10:22 AM

Nirman Doshi said:

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

Vadodara

# December 9, 2008 2:38 AM

Arda said:

Thanks egoldin, that works very well and it s very useful....

# July 13, 2009 9:10 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)