asp.net 表单自动提交
asp.net form getting auto submitted
我试图在提交 asp.net 表单之前进行验证。
然而,它不断被提交。下面是代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Register.aspx.cs" Inherits="Register" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
#form1 {
height: 254px;
width: 905px;
}
.tabClass {
margin-top: 10%;
}
input {
margin-top: 50px;
}
#Name {
margin-right: 58px;
}
#uName {
margin-right: 55px;
}
#p1 {
margin-right: 66px;
}
#Label2 {
margin-right: 20px;
}
</style>
<script type="text/javascript">
function DoValidation(parameter) {
document.getElementById("Button2").click();
var prompt = "";
var a = document.getElementById("TextBox_FName").value;
if (a == "")
prompt += "Please Enter Full Name. ";
a = document.getElementById("TextBox_UName").value;
if (a == "")
prompt += "Please User Name. ";
a = document.getElementById("Password1").value;
if (a == "")
prompt += "Please Enter Password. ";
if (a != document.getElementById("Password2").value)
prompt += "Entered Passwords Don't match. ";
if (prompt === "") {
document.getElementById("<%=Button2.ClientID%>").click();
} else {
alert(prompt);
return false;
}
}
</script>
</head>
<body>
<div style="margin-left: 30%;">
<form id="form1" runat="server">
<div>
<asp:Label ID="Name" runat="server" Text="Full Name" CssClass="tabClass"></asp:Label>
<asp:TextBox ID="TextBox_FName" Height="25px" Width="300px" runat="server" ></asp:TextBox>
</div>
<asp:Label ID="uName" runat="server" Text="User Name" CssClass="tabClass"></asp:Label>
<asp:TextBox ID="TextBox_UName" Height="25px" Width="200px" runat="server"></asp:TextBox>
<br />
<asp:Label ID="p1" runat="server" Text="Password" CssClass="tabClass"> </asp:Label>
<asp:TextBox ID="Password1" runat="server" Height="25px" TextMode="Password" Width="200px"></asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="Retype Password"></asp:Label>
<asp:TextBox ID="Password2" runat="server" Height="25px" TextMode="Password" Width="200px"></asp:TextBox>
<p>
<asp:Button ID="Button3" runat="server" OnClientClick="return !!DoValidation()" Text="Register" style="display:none;" />
</p>
<asp:Button ID="Button2" runat="server" OnClick="Button1_Click" Text="HiddenRegister" style="display:none;"/>
</form>
<button onclick="DoValidation()">Reg1 </button>
</div>
</body>
</html>
即使我收到"doValidation() 方法的其他条件"的警报提示,我的表单也总是被发布。
啊,删除DoValidation函数中的第一行:
document.getElementById("Button2").click();
试试这个,你不会重新设置函数所以你必须返回函数...像下面....
<button onclick="return DoValidation()">Reg1 </button>
相关文章:
- Jquery提交表单而不刷新
- 如何在提交表单时将PHP变量传递到Javascript cookie中
- 每次提交表单时都会重新加载网页
- Razor中的自动提交表单
- 使用 JavaScript 自动提交表单
- 点击相同的按钮打开模型,然后提交表单
- 添加和删除隐藏字段数组中的值,而不提交表单
- 使用Ajax提交表单
- jQuery:使用“jQuery验证”后无法提交表单's远程验证
- 如何在不重新加载的情况下提交表单,并使用Node+Express将数据传递回同一页面
- 有登录表单时无法提交表单
- 带有select的jquery提交表单不起作用
- 如何防止回车键提交表单,但仍然允许回车工作
- 使用按钮和单选按钮提交表单,但始终使用相同的值
- 在提交表单之前确定重复值
- 如何创建动态ajax提交表单
- HTML提交表单,同时包含空字段检查和按钮隐藏
- 如何使用jQueryAjax使用动态html输入texbox提交表单
- 当触发下拉列表的onchange事件时,使用JavaScript提交表单
- 提交表单后,Watir文本框输入未持续(重置为以前的文本框输入)