我有一个登录下拉菜单的问题。当我按下登录链接时,下拉菜单会向下滑动。我想要的是当给出错误的凭据时不要回发(刷新),这样下拉菜单将保持打开状态,让用户输入正确的密码!
我试过 OnClientClick="return false;" 但这会禁用我的 asp:button 的 onclick 事件。
我背后的代码:
string insCmd = "SELECT ID_USER FROM users WHERE username = @LoginEmail AND password = @passwd;";
SqlCommand Login = new SqlCommand(insCmd, con);
Login.Parameters.AddWithValue("@LoginEmail", txtLoginEmail.Text);
Login.Parameters.AddWithValue("@passwd", txtLoginPassword.Text);
try
{
SqlDataReader dr = Login.ExecuteReader();
SqlDataReader dr2;
if (dr == null || !dr.HasRows)
{
litErrorLogin.Text = "<span>Error:Wrong Credentials</span>";
//btnLogin.OnClientClick = "return false;";
return;
}
while (dr.Read())
{
Session["UserID"] = dr.GetInt32(0);
}
我的html代码:
<div id="bb_loginForm">
<div class="bg_loginForm">
<span style="font-size:11.5px;font-weight:bold">Log in to Account</span> <a class="bb_linkLoginHeaderHide" href="#" title="Hide">
Hide</a>
<br />
<div class="f_username">
<label for="txtLoginEmail" id="labelUser">
Email
</label>
<br />
<asp:TextBox class="text-input" ID="txtLoginEmail" runat="server" Height="15px" Width="130px"></asp:TextBox>
</div>
<div class="f_password">
<label for="txtLoginPassoword" id="labelPassword">
Password
</label>
<br />
<asp:TextBox class="text-input" ID="txtLoginPassword" runat="server" Height="15px" Width="130px"
TextMode="Password"></asp:TextBox>
</div>
<br />
<div class="f_login">
<!--src="../images/GreyButton.png" class="submit btn primary-btn" onclick="btnLogin_Click"-->
<asp:Button class="submit google-button" ID="btnLogin" onclick="btnLogin_Click" runat="server" Text="Log in" />
<br />
<asp:CheckBox ID="chkRememberLogin" runat="server" />
<label class="smaller" for="chkRememberLogin" id="labelrememberusername">Remember me
</label>
<br />
<a title="Forgot your login info?" href="#" class="underlineHover">Forgot your login
info? </a>
<br />
<asp:Literal ID="litErrorLogin" runat="server"></asp:Literal>
</div>
</div>
</div>