ASP:Login : 输入用户名后密码不会自动完成
ASP:Login : Password not autocomplete after enter Username
我使用 ASP:Login 为我的页面获取登录表单。
现在我有 2 个问题,我试图找到一个解决方案但是......@_@。
现在,我进入登录页面。键入用户,键入密码,然后输入
问题 1:输入键未聚焦到登录按钮。这意味着,我必须单击“登录”按钮才能登录。在这种情况下如何设置默认按钮?
问题 2:好的。已登录。浏览器(Chrome、Firefox ...)要求保存密码。好的。已保存。
然后,当我在另一个时间进入登录页面时。当我输入用户名时密码不会自动填充(浏览器仍然保存用户名和密码信息)。
我的设置或代码有误吗? :(
我的代码:
<asp:Login ID="Login1" runat="server" BackColor="transparent" Font-Names="Verdana"
Font-Size="0.8em" ForeColor="#333333" Height="147px"
LoginButtonText="Đăng nhập" onloggingin="Login1_LoggingIn"
RememberMeText="Nhớ password cho lần đăng nhập sau."
TitleText="Đăng nhập hệ thống" Width="400px"
FailureText="Đăng nhập không thành công!"
HelpPageText="Anh, chị là khách hàng? "
onauthenticate="Login1_Authenticate"
PasswordRequiredErrorMessage="Chưa nhập Password."
UserNameRequiredErrorMessage="Chưa nhập User Name." BorderColor="#339933"
BorderStyle="Solid" BorderWidth="1px" CssClass="border">
<HyperLinkStyle Font-Size="10pt" HorizontalAlign="Left" />
<InstructionTextStyle Font-Italic="True" ForeColor="Black" />
<LabelStyle Wrap="True" />
<LayoutTemplate>
<table cellpadding="4" cellspacing="0" style="border-collapse:collapse;">
<tr>
<td>
<table cellpadding="0" style="height:147px;width:400px;">
<tr>
<td align="left" colspan="2"
style="color:White;background-color:#006D55;font-size:11pt;font-weight:bold;height:25px;white-space:nowrap; padding-left: 10px;">
Đăng nhập hệ thống</td>
</tr>
<tr>
<td align="left" colspan="2">
<br>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
</td>
<td align="left">
<asp:TextBox ID="UserName" runat="server" Font-Size="10pt" Height="22px"
Width="250px" CssClass="border"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server"
ControlToValidate="UserName" ErrorMessage="Chưa nhập User Name."
ToolTip="Chưa nhập User Name." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
</td>
<td align="left">
<asp:TextBox ID="Password" runat="server" Font-Size="10pt" Height="22px"
TextMode="Password" Width="250px" CssClass="border" Wrap="False"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server"
ControlToValidate="Password" ErrorMessage="Chưa nhập Password."
ToolTip="Chưa nhập Password." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="left" colspan="2">
<br />
</td>
</tr>
<tr>
<td colspan="2">
<asp:CheckBox ID="RememberMe" runat="server"
Text="Nhớ password cho lần đăng nhập sau." AutoPostBack="True" />
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color:Red;">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="LoginButton" runat="server" BackColor="#006D55"
BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" CommandName="Login"
Font-Names="Verdana" Font-Size="11pt" ForeColor="White" Height="25px"
Text="Login" ValidationGroup="Login1" Width="100%" />
</td>
</tr>
<tr>
<td align="left" colspan="2">
<hr />
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:HyperLink ID="HelpLink" runat="server" Font-Size="10pt">Anh, chị chưa có tài khoản ? </asp:HyperLink>
</td>
</tr>
<tr align="center">
<td align="left" colspan="2" style="padding-top: 10px;">
<dx:ASPxButton ID="ASPxButton1" runat="server" Text="Tạo tài khoản"
onclick="ASPxButton1_Click" Width="100%"
Font-Size="11pt" Font-Names="Verdana" BackColor="White"
ForeColor="#006D55" Height="20px" HorizontalAlign="Center">
<HoverStyle BackColor="#A6DDD1" Font-Bold="True">
</HoverStyle>
<Border BorderColor="#006D55" />
</dx:ASPxButton>
</td>
</tr>
</table>
</td>
</tr>
</table>
</LayoutTemplate>
<LoginButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid"
BorderWidth="1px" Font-Names="Verdana" Font-Size="10pt" ForeColor="#284775"
Height="25px" Width="80px" />
<TextBoxStyle Font-Size="10pt" Height="22px" Width="150px" />
<TitleTextStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="10pt"
ForeColor="White" Height="25px" HorizontalAlign="Left" Wrap="False" />
sp_compa.Service1 ws = new sp_compa.Service1();
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack) return;
Session["STATION_CODE"] = "";
Session["COMP_CODE"] = "";
Session["COMP_NAME"] = "";
Session["UserName"] = "";
Session["PassWord"] = "";
Session.Timeout = 120;
}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
string user = this.Login1.UserName.Trim();
string password = this.Login1.Password.Trim();
DataSet ds = sp.get_user_new(user, clsdb.identity);
Session["dsuser"] = ds;
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
DataRow row = ds.Tables[0].Rows[0];
if (this.Login1.Password.ToUpper().Trim().Equals(row["PassWord"].ToString().ToUpper()))
{
e.Authenticated = true;
Session["UserName"] = user;
Session["PassWord"] = password;
Session["COMP_CODE_User"] = row["COMP_CODE"];
if ((bool)row["KH"] == false)
Response.Redirect("~/Home.aspx");
else
{
Response.Redirect("~/ttkh.aspx");
}
}
else
{
}
}
e.Authenticated = false;
}
问题 1 的解决方案是使用 Asp.Net 面板并使用它的 Defauenter code here
ltButton 属性.
例如,
<asp:Login ID="Login1" runat="server">
<LayoutTemplate>
<asp:Panel ID="Panel1" runat="server" DefaultButton = "LoginButton">
<table cellpadding="4" cellspacing="0" style="border-collapse:collapse;">
<tr>
<td>
<table cellpadding="0" style="height:147px;width:400px;">
<tr>
<td align="left" colspan="2"
style="color:White;background-color:#006D55;font-size:11pt;font-weight:bold;height:25px;white-space:nowrap; padding-left: 10px;">
Đăng nhập hệ thống</td>
</tr>
<tr>
<td align="left" colspan="2">
<br>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
</td>
<td align="left">
<asp:TextBox ID="UserName" runat="server" Font-Size="10pt" Height="22px"
Width="250px" CssClass="border"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server"
ControlToValidate="UserName" ErrorMessage="Chưa nhập User Name."
ToolTip="Chưa nhập User Name." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
</td>
<td align="left">
<asp:TextBox ID="Password" runat="server" Font-Size="10pt" Height="22px"
TextMode="Password" Width="250px" CssClass="border" Wrap="False"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server"
ControlToValidate="Password" ErrorMessage="Chưa nhập Password."
ToolTip="Chưa nhập Password." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="left" colspan="2">
<br />
</td>
</tr>
<tr>
<td colspan="2">
<asp:CheckBox ID="RememberMe" runat="server"
Text="Nhớ password cho lần đăng nhập sau." AutoPostBack="True" />
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color:Red;">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="LoginButton" runat="server" BackColor="#006D55"
BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" CommandName="Login"
Font-Names="Verdana" Font-Size="11pt" ForeColor="White" Height="25px"
Text="Login" ValidationGroup="Login1" Width="100%" />
</td>
</tr>
<tr>
<td align="left" colspan="2">
<hr />
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:HyperLink ID="HelpLink" runat="server" Font-Size="10pt">Anh, chị chưa có tài khoản ? </asp:HyperLink>
</td>
</tr>
<tr align="center">
<td align="left" colspan="2" style="padding-top: 10px;">
<dx:ASPxButton ID="ASPxButton1" runat="server" Text="Tạo tài khoản"
onclick="ASPxButton1_Click" Width="100%"
Font-Size="11pt" Font-Names="Verdana" BackColor="White"
ForeColor="#006D55" Height="20px" HorizontalAlign="Center">
<HoverStyle BackColor="#A6DDD1" Font-Bold="True">
</HoverStyle>
<Border BorderColor="#006D55" />
</dx:ASPxButton>
</td>
</tr>
</table>
</td>
</tr>
</table>
</asp:Panel>
</LayoutTemplate>
</asp:Login>
关于问题2,不知道你的浏览器为什么不把密码推送回文本框。
我使用 ASP:Login 为我的页面获取登录表单。 现在我有 2 个问题,我试图找到一个解决方案但是......@_@。 现在,我进入登录页面。键入用户,键入密码,然后输入
问题 1:输入键未聚焦到登录按钮。这意味着,我必须单击“登录”按钮才能登录。在这种情况下如何设置默认按钮?
问题 2:好的。已登录。浏览器(Chrome、Firefox ...)要求保存密码。好的。已保存。 然后,当我在另一个时间进入登录页面时。当我输入用户名时密码不会自动填充(浏览器仍然保存用户名和密码信息)。 我的设置或代码有误吗? :( 我的代码:
<asp:Login ID="Login1" runat="server" BackColor="transparent" Font-Names="Verdana"
Font-Size="0.8em" ForeColor="#333333" Height="147px"
LoginButtonText="Đăng nhập" onloggingin="Login1_LoggingIn"
RememberMeText="Nhớ password cho lần đăng nhập sau."
TitleText="Đăng nhập hệ thống" Width="400px"
FailureText="Đăng nhập không thành công!"
HelpPageText="Anh, chị là khách hàng? "
onauthenticate="Login1_Authenticate"
PasswordRequiredErrorMessage="Chưa nhập Password."
UserNameRequiredErrorMessage="Chưa nhập User Name." BorderColor="#339933"
BorderStyle="Solid" BorderWidth="1px" CssClass="border">
<HyperLinkStyle Font-Size="10pt" HorizontalAlign="Left" />
<InstructionTextStyle Font-Italic="True" ForeColor="Black" />
<LabelStyle Wrap="True" />
<LayoutTemplate>
<table cellpadding="4" cellspacing="0" style="border-collapse:collapse;">
<tr>
<td>
<table cellpadding="0" style="height:147px;width:400px;">
<tr>
<td align="left" colspan="2"
style="color:White;background-color:#006D55;font-size:11pt;font-weight:bold;height:25px;white-space:nowrap; padding-left: 10px;">
Đăng nhập hệ thống</td>
</tr>
<tr>
<td align="left" colspan="2">
<br>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
</td>
<td align="left">
<asp:TextBox ID="UserName" runat="server" Font-Size="10pt" Height="22px"
Width="250px" CssClass="border"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server"
ControlToValidate="UserName" ErrorMessage="Chưa nhập User Name."
ToolTip="Chưa nhập User Name." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
</td>
<td align="left">
<asp:TextBox ID="Password" runat="server" Font-Size="10pt" Height="22px"
TextMode="Password" Width="250px" CssClass="border" Wrap="False"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server"
ControlToValidate="Password" ErrorMessage="Chưa nhập Password."
ToolTip="Chưa nhập Password." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="left" colspan="2">
<br />
</td>
</tr>
<tr>
<td colspan="2">
<asp:CheckBox ID="RememberMe" runat="server"
Text="Nhớ password cho lần đăng nhập sau." AutoPostBack="True" />
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color:Red;">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="LoginButton" runat="server" BackColor="#006D55"
BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" CommandName="Login"
Font-Names="Verdana" Font-Size="11pt" ForeColor="White" Height="25px"
Text="Login" ValidationGroup="Login1" Width="100%" />
</td>
</tr>
<tr>
<td align="left" colspan="2">
<hr />
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:HyperLink ID="HelpLink" runat="server" Font-Size="10pt">Anh, chị chưa có tài khoản ? </asp:HyperLink>
</td>
</tr>
<tr align="center">
<td align="left" colspan="2" style="padding-top: 10px;">
<dx:ASPxButton ID="ASPxButton1" runat="server" Text="Tạo tài khoản"
onclick="ASPxButton1_Click" Width="100%"
Font-Size="11pt" Font-Names="Verdana" BackColor="White"
ForeColor="#006D55" Height="20px" HorizontalAlign="Center">
<HoverStyle BackColor="#A6DDD1" Font-Bold="True">
</HoverStyle>
<Border BorderColor="#006D55" />
</dx:ASPxButton>
</td>
</tr>
</table>
</td>
</tr>
</table>
</LayoutTemplate>
<LoginButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid"
BorderWidth="1px" Font-Names="Verdana" Font-Size="10pt" ForeColor="#284775"
Height="25px" Width="80px" />
<TextBoxStyle Font-Size="10pt" Height="22px" Width="150px" />
<TitleTextStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="10pt"
ForeColor="White" Height="25px" HorizontalAlign="Left" Wrap="False" />
sp_compa.Service1 ws = new sp_compa.Service1();
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack) return;
Session["STATION_CODE"] = "";
Session["COMP_CODE"] = "";
Session["COMP_NAME"] = "";
Session["UserName"] = "";
Session["PassWord"] = "";
Session.Timeout = 120;
}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
string user = this.Login1.UserName.Trim();
string password = this.Login1.Password.Trim();
DataSet ds = sp.get_user_new(user, clsdb.identity);
Session["dsuser"] = ds;
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
DataRow row = ds.Tables[0].Rows[0];
if (this.Login1.Password.ToUpper().Trim().Equals(row["PassWord"].ToString().ToUpper()))
{
e.Authenticated = true;
Session["UserName"] = user;
Session["PassWord"] = password;
Session["COMP_CODE_User"] = row["COMP_CODE"];
if ((bool)row["KH"] == false)
Response.Redirect("~/Home.aspx");
else
{
Response.Redirect("~/ttkh.aspx");
}
}
else
{
}
}
e.Authenticated = false;
}
问题 1 的解决方案是使用 Asp.Net 面板并使用它的 Defauenter code here
ltButton 属性.
例如,
<asp:Login ID="Login1" runat="server">
<LayoutTemplate>
<asp:Panel ID="Panel1" runat="server" DefaultButton = "LoginButton">
<table cellpadding="4" cellspacing="0" style="border-collapse:collapse;">
<tr>
<td>
<table cellpadding="0" style="height:147px;width:400px;">
<tr>
<td align="left" colspan="2"
style="color:White;background-color:#006D55;font-size:11pt;font-weight:bold;height:25px;white-space:nowrap; padding-left: 10px;">
Đăng nhập hệ thống</td>
</tr>
<tr>
<td align="left" colspan="2">
<br>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
</td>
<td align="left">
<asp:TextBox ID="UserName" runat="server" Font-Size="10pt" Height="22px"
Width="250px" CssClass="border"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server"
ControlToValidate="UserName" ErrorMessage="Chưa nhập User Name."
ToolTip="Chưa nhập User Name." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
</td>
<td align="left">
<asp:TextBox ID="Password" runat="server" Font-Size="10pt" Height="22px"
TextMode="Password" Width="250px" CssClass="border" Wrap="False"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server"
ControlToValidate="Password" ErrorMessage="Chưa nhập Password."
ToolTip="Chưa nhập Password." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="left" colspan="2">
<br />
</td>
</tr>
<tr>
<td colspan="2">
<asp:CheckBox ID="RememberMe" runat="server"
Text="Nhớ password cho lần đăng nhập sau." AutoPostBack="True" />
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color:Red;">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="LoginButton" runat="server" BackColor="#006D55"
BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" CommandName="Login"
Font-Names="Verdana" Font-Size="11pt" ForeColor="White" Height="25px"
Text="Login" ValidationGroup="Login1" Width="100%" />
</td>
</tr>
<tr>
<td align="left" colspan="2">
<hr />
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:HyperLink ID="HelpLink" runat="server" Font-Size="10pt">Anh, chị chưa có tài khoản ? </asp:HyperLink>
</td>
</tr>
<tr align="center">
<td align="left" colspan="2" style="padding-top: 10px;">
<dx:ASPxButton ID="ASPxButton1" runat="server" Text="Tạo tài khoản"
onclick="ASPxButton1_Click" Width="100%"
Font-Size="11pt" Font-Names="Verdana" BackColor="White"
ForeColor="#006D55" Height="20px" HorizontalAlign="Center">
<HoverStyle BackColor="#A6DDD1" Font-Bold="True">
</HoverStyle>
<Border BorderColor="#006D55" />
</dx:ASPxButton>
</td>
</tr>
</table>
</td>
</tr>
</table>
</asp:Panel>
</LayoutTemplate>
</asp:Login>
关于问题2,不知道你的浏览器为什么不把密码推送回文本框。