如何在 asp.net 中更新服务器端执行的 UI 按钮文本

How to update the UI button text from server side execution in asp.net?

本文关键字:执行 UI 按钮 文本 服务器端 更新 asp net      更新时间:2023-09-26

>我正在使用如下所示的登录控件,

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

在身份验证时,我们需要更改登录按钮文本并重定向到默认.aspx页面。我尝试使用RegisterStartupScript,线程都对我不起作用。如果您对从事件中更新 UI 按钮文本有任何建议,请告诉我Login1_Authenticate。

这对

我有用:

添加此事件: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事件执行相同的操作。