gpt4 book ai didi

javascript - asp.net 表单自动提交

转载 作者:行者123 更新时间:2023-12-02 16:45:38 25 4
gpt4 key购买 nike

我试图在提交 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();

关于javascript - asp.net 表单自动提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27139944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com