2015-01-07 20 views
0

我使用類似下面登錄控制,如何在asp.net中更新服務器端執行的UI按鈕文本?

<asp:Login ID="Login1" runat="server" DestinationPageUrl="default.aspx" OnAuthenticate="Login1_Authenticate" RenderOuterTable="false"> 
    <LayoutTemplate> 
    <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal> 
    <asp:TextBox ID="UserName" name="UserName" runat="server" CssClass="form-control" placeholder="Username"></asp:TextBox> 

    <asp:TextBox ID="Password" runat="server" TextMode="Password" CssClass="form-control" placeholder="Password"></asp:TextBox> 

    <asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In &nbsp;&nbsp;" /> 
    </LayoutTemplate> 
</asp:Login> 

在驗證我們需要改變登錄按鈕文字,並重定向到Default.aspx的page.I試圖用的RegisterStartupScript和線程都爲me.Please沒有工作讓我知道如果您有任何關於更新來自Login1_Authenticate事件的UI按鈕文本的建議。

+0

什麼時候你想改變按鈕的文字?而其認證? – Rohit

+0

有兩個功能,一個是它會認證的,一段時間後它會重定向。一旦通過驗證,我們需要更新ui中的按鈕文本。我試圖更新按鈕文本,但它不會反映,直到執行結束。 –

+0

@akshaybogar無論哪種方式,在點擊** Login **按鈕之後,您將用戶重定向到另一個頁面。 ***更改按鈕文本太晚;用戶無論如何都看不到新的按鈕文本***你想達到什麼目的?你想根據用戶的角色將用戶重定向到特定的頁面嗎? – Win

回答

0

這是爲我工作:

添加此事件:OnLoggedIn = 「Login1_LoggedIn」 和代碼隱藏:

protected void Login1_LoggedIn(object sender, EventArgs e) 
{ 
    Response.Redirect("www."); 

    //OR 

    var btn = ((System.Web.UI.WebControls.Button)(Login1.FindControl("LoginButton"))); 
    if (btn != null) 
     btn.Text = "REDIRECT"; 
} 

或者做Login1_Authenticate事件一樣。

+0

我嘗試在Login1_Logged事件中設置UI按鈕文本。因爲我試圖重定向到OnAuthnetication事件中的其他頁面,它不適合我。我們可以在重定向到其他頁面之前執行事件時設置UI按鈕文本...? –