Bring back the ChangePasswordTemplate from SuccessTemplate

2008-09-12

Recently I am developing a user admin module. I have a GridView control and a ChangePassword control in the page.

The admin could choose the user from the GridView and change the user's password in the ChangePassword control. When the admin completes the password change, the SuccessTemplate is shown. All works fine at this stage.

But when the admin selects another user from the GridView, the ChangePassword control still stays in the SuccessTemplate view. The system is not able to switch it back to the ChangePasswordTemplate view. There are not any properties within the ChangePassword control related to this.

I am looking for something be quite similar to the method in DetailsView to switch from different modes, e.g. DetailsView1.ChangeMode(DetailsViewMode.Edit).

There is an internal View CurrentView (ChangePassword, Success) property in changePassword control, but looks like it doesn't expose a public method to change CurrentView.
Finally I found this blog entry:
http://msmvps.com/blogs/egoldin/archive/2007/10/30/reseting-changepassword-control.aspx

I use the code provided and solve the problem.

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

Note: 

The Copyright © of the code above and all credits are the original author (Eliyahu Goldin http://usableasp.net/).

The original post is
http://msmvps.com/blogs/egoldin/archive/2007/10/30/reseting-changepassword-control.aspx

I post the code here for my own reference only.


Previous Article:
Solution to capture read only textbox value in ASP.Net 2.0


Next Article:
Solution for database execution timeout problem in ASP.Net application



Categories

Search eGaWa.Blog

Keyword 1
Keyword 2
Keyword 3
Category
Search

Search Web

Reload Page