我想在用户输入他/她的用户名和/或密码不正确后,到达并清除用户名文本框(位于登录框中)。我试过了;
((TextBox)loginBox.FindControl("UserName")).Text = "";
但我无法清除用户名文本框或关注那里?
答案 0 :(得分:2)
在登录工具中,可以通过以下代码进行聚焦:
loginBox.FindControl("UserName").Focus();
但据我所知,无法清除UserName文本。我不能像传统方法那样被清除。同样,大多数网站都保留用户名,但干净的密码字段甚至是用户提供的错误信息。
您应该更改" UserName"文本框属性从代码到普通文本框属性。
答案 1 :(得分:0)
似乎我们需要在某些事件中将UserName.Text和Login.UserName设置为空字符串,例如Login.OnLoginError:
<script runat="server">
void OnLoginError(object sender, EventArgs e)
{
((TextBox)Login1.FindControl("UserName")).Text="";
Response.Write("Hello!");
Login1.UserName = "";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Login ID="Login1" runat="server" OnLoginError="OnLoginError">
</asp:Login>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
</form>
</body>
</html>