Jquery ASP.NET在服务器上单击,然后单击客户端
我搞不懂这个 这是我的login.aspxJquery ASP.NET在服务器上单击,然后单击客户端,jquery,asp.net,onclick,Jquery,Asp.net,Onclick,我搞不懂这个 这是我的login.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="EcnManager.Web.Login" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="EcnManager.Web.Login" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="Content/bootstrap.min.css" rel="stylesheet" />
<script src="Scripts/jquery-1.9.1.js"></script>
</head>
<body>
<div class="container">
<div class="row" style="height:30px">
<div class="col-lg-12"></div>
</div>
<div class="row">
<div class="col-lg-4"></div>
<div class="col-lg-4">
<div class="panel panel-primary">
<div class="panel-heading">ECN Manager Login</div>
<div class="panel-body">
<form role="form" runat="server">
<div class="form-group">
<label for="txtUserName" class="control-label">Login Name</label>
<input id="txtUserName" runat="server" class="form-control" placeholder="Login Name"/>
<%--<asp:TextBox ID="txtUserName" runat="server" CssClass="form-control"></asp:TextBox>--%>
</div>
<div class="form-group has-error">
<label for="txtPassword" class="control-label">Password</label>
<input id="txtPassword" runat="server" type="password" class="form-control" placeholder="Password"/>
<%--<asp:TextBox ID="txtPassword" runat="server" TextMode="Password" CssClass="form-control" ></asp:TextBox>--%>
</div>
<div class="form-group">
<div class="row">
<div class="col-lg-3">
<%--<input runat="server" id="btnLogin" type="button" value="Login" class="btn btn-default" onserverclick="btnLogin_Click"/>--%>
<asp:Button ID="btnLogin" runat="server" class="btn btn-default" Text="Login" OnClientClick="btnLoginClick()" OnClick="btnLogin_Click" />
</div>
<div class="col-lg-9">
<asp:CheckBox ID="chkRemeberMe" runat="server" />
<label class="text-center">Remember Me</label>
</div>
</div>
</div>
</form>
</div>
<div class="panel-footer"></div>
</div>
</div>
<div class="col-lg-4"></div>
</div>
<div class="row" style="height:30px">
<div class="col-lg-12"></div>
</div>
</div>
<script type="text/javascript">
function btnLoginClick() {
alert("im here");
return false;
};
</script>
</body>
</html>
ECN管理器登录
登录名
密码
记得我吗
函数btnLoginClick(){
警惕(“我在这里”);
返回false;
};
当我运行并单击btnLogin时,我确实会得到“im here”,但它也会启动服务器端事件。我将false传递给btnLoginClick以防止这种情况发生。我错过了什么吗。非常感谢您的帮助
编辑
尤里·加兰特的回答解决了这个问题。谢谢
现在我也在尝试做jcalabris的答案,这样我就可以学习了
因此,我做了以下操作,没有使用asp按钮,而是使用button类型的输入
<input runat="server" id="btnLogin" type="button" value="Login" class="btn btn-default" onserverclick="btnLogin_Click"/>
<%--<asp:Button ID="btnLogin" runat="server" class="btn btn-default" Text="Login" OnClientClick="btnLoginClick()" OnClick="btnLogin_Click" />--%>
我修改了javascript代码如下
<script type="text/javascript">
$("#btnLogin").click(function(){
event.preventDefault();
return false;
});
</script>
$(“#btnLogin”)。单击(函数(){
event.preventDefault();
返回false;
});
这是正确的吗?对我来说它不起作用
我还尝试了以下方法
<script type="text/javascript">
$("#btnLogin").click(function(e){
e.preventDefault();
return false;
});
</script>
$(“#btnLogin”)。单击(函数(e){
e、 预防默认值();
返回false;
});
我想我做错了什么
非常感谢你的帮助
谢谢您还必须在按钮声明中返回false 而不是
OnClientClick="btnLoginClick()"
试试这个:
OnClientClick="return btnLoginClick()"
由于您的
函数btnLoginClick
已经返回false-上面将结果返回到事件,有效地取消了回发我看到OnClientClick
触发,但是我们的onserver click
没有触发。。。为什么会这样?在OnClientClick中使用“return”是否有问题?