我驗證了沒有乾淨的方法來做到這一點(通過ILSpy),請參閱下面的例子,以稍微骯髒的方式。基本上我們使用反射來獲得CurrentView
屬性,這是一個內部屬性,然後我們將PasswordReset控件的當前視圖設置爲以下三種狀態之一:用戶名(0),問題(1)或成功(2)。
設計師
<form id="form1" runat="server">
<div>
<asp:PasswordRecovery ID="pwr" runat="server"></asp:PasswordRecovery>
</div>
<span>Set Recover State: </span>
<asp:RadioButtonList ID="rblChangeState" runat="server" AutoPostBack="True"
onselectedindexchanged="rblChangeState_SelectedIndexChanged">
<asp:ListItem Text="Username" Value="0" />
<asp:ListItem Text="Question" Value="1" />
<asp:ListItem Text="Success" Value="2" />
</asp:RadioButtonList>
</form>
代碼隱藏
protected void rblChangeState_SelectedIndexChanged(object sender, EventArgs e)
{
Type t = pwr.GetType();
PropertyInfo viewSetter = t.GetProperty("CurrentView", BindingFlags.Default | BindingFlags.NonPublic | BindingFlags.Instance);
viewSetter.SetValue(pwr, Convert.ToInt32(rblChangeState.SelectedValue), null);
}
所以定義事件點擊按鈕。 – 2012-07-10 19:00:13
謝謝,但這沒有幫助。我在問如何重置控制狀態,而不是如何處理按鈕點擊。 – 2012-07-10 19:20:26