单击ASP.NET登录窗体更改登录按钮cssClass



我有以下代码,前端(只是相关代码):

<asp:Login ID="Login1" runat="server" OnAuthenticate="ValidateUser">
<td align="right" colspan="2">
<asp:Button ID="LoginButton" runat="server" CssClass="btn btn-success" CommandName="Login" Text="Log Ind" ValidationGroup="Login1" />
</td>

然后在后端代码中,我希望在单击LoginButton时更改其背景颜色。但我似乎无法抓住ValidateUser函数中的按钮?

我只有以下选项:

Login1.LoginButtonImageUrl
Login1.LoginButtonStyle
Login1.LoginButtonText
Login1.LoginButtonType

当您没有或无法访问asp控件上的所有属性时,即在登录表单中,诀窍是首先在该表单中找到它,然后按您喜欢的方式操作。在您的情况下,代码将为:

    // first find and capture the control
    var oLoginButton = (Button)Login1.FindControl("LoginButton");
    // now you have all propeties of the asp.net control
    oLoginButton.BackColor = System.Drawing.Color.Red

最新更新