好吧,我有一个登录页面(也出现在注册页面中),当我输入密码登录后按Enter键时,它会将我重定向到默认页面,但不会做任何其他事情 - 但是当我点击登录时按钮,它会成功登录。为什么会这样?有没有办法解决它,修复它?
例如,这是我的login.aspx页面:
<%@ Page Title="התחברות" Language="C#" MasterPageFile="~/MasterPageTest.master" AutoEventWireup="true" CodeFile="login.aspx.cs" Inherits="login" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<br />
<center><b>
<asp:Login ID="Login1" runat="server"
LoginButtonText="התחבר" PasswordLabelText="סיסמא:" TitleText="<u><font size=4>התחברות</font></u>"
UserNameLabelText="שם משתמש:" RememberMeText="זכור אותי"
TextLayout="TextOnTop">
<LayoutTemplate>
<table cellpadding="1" cellspacing="0" style="border-collapse:collapse;" dir="rtl">
<tr>
<td>
<table cellpadding="0">
<tr>
<td align="center">
<u><font size="4">התחברות</font></u></td>
</tr>
<tr>
<td>
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">שם משתמש:</asp:Label>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="UserName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server"
ControlToValidate="UserName" ErrorMessage="User Name is required."
ToolTip="User Name is required." ValidationGroup="Login1"><font color="red">*</font></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">סיסמא:</asp:Label>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server"
ControlToValidate="Password" ErrorMessage="Password is required."
ToolTip="Password is required." ValidationGroup="Login1"><font color="red">*</font></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:CheckBox ID="RememberMe" runat="server" Text="זכור אותי" />
</td>
</tr>
<tr>
<td align="center" style="color:Red;">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
<tr>
<td align="right">
<asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="התחבר"
ValidationGroup="Login1" />
<br />
<asp:LinkButton ID="ForgotPassLnk" runat="server" Text="שכחתי סיסמא" OnClick="ForgotPassLnk_Click"></asp:LinkButton>
</td>
</tr>
</table>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:Login>
</b></center>
</asp:Content>
答案 0 :(得分:0)
一个解决方案是:
<asp:TextBox ID="Password" runat="server" TextMode="Password" onkeypress="return EnterEvent(event)"></asp:TextBox>
<强> JS 强>
function EnterEvent(e) {
if (e.keyCode == 13) {
//login code
}
}