按钮不会导致c#函数运行
本文关键字:函数 运行 按钮 | 更新日期: 2023-09-27 18:28:39
这是我的代码
<body>
<form id="form1" runat="server">
<div class="jumbotron" >
<h1>Welcome to BodySpace</h1>
<div class="navbar-collapse collapse">
<!--<form class="form-signin" id="SignInForm" action="Default.aspx/#SignInForm"> -->
<table><tr><td> <asp:TextBox type="email" runat="server" name="email" id="email" ValidationGroup="LogIn" class="input-block-level" placeholder="Email" required /></td>
<td> <asp:TextBox type="password" runat="server" name="pass" id="pass" ValidationGroup="LogIn" class="input-block-level" placeholder="Password" required /></td>
<td> <asp:Button runat="server" class="btn btn-success" text="Sign-In" ID="SignInButton" ValidationGroup="LogIn" onclick="SignInButton_Click" /></td><td><label runat="server" id="failedLogin">Incorrect email and password combination</label></td></tr>
<tr><td></td><td></td><td><a class="btn btn-block btn-social btn-facebook"><i class="fa fa-facebook"></i>Sign in with Facebook</a></td>
</tr></table><!--</form>-->
</div>
</div>
<!--<form class="form-group" id="RegisterForm" action="Default.aspx/#RegisterForm"> -->
<table><tr><td>
<h3>This website and all of it's
</h3>
<h3>contents are and will remain free</h3>
<table><tr><td><asp:TextBox runat="server" type="text" name="fNameReg" id="fNameReg" ValidationGroup="Register" class="form-control" placeholder="First name" required /></td>
<td><asp:TextBox type="text" runat="server" name="lNameReg" id="lNameReg" ValidationGroup="Register" class="form-control" placeholder="Last name" required /></td>
</tr></table>
<br /><asp:TextBox runat="server" type="email" name="emailReg" id="emailReg" ValidationGroup="Register" class="form-control" placeholder="Your email adress" title="Must be a valid email adress" required pattern="^[0-9a-zA-Z]+([0-9a-zA-Z]*[-._+])*[0-9a-zA-Z]+@[0-9a-zA-Z]+([-.][0-9a-zA-Z]+)*([0-9a-zA-Z]*[.])[a-zA-Z]{2,6}$" />
<br /><asp:TextBox runat="server" type="text" name="emailRegCheck" id="emailRegCheck" ValidationGroup="Register" class="form-control" placeholder="Retype your email adress" required />
<br /><asp:TextBox runat="server" type="password" name="passwordReg" id="passwordReg" ValidationGroup="Register" class="form-control" placeholder="Password" title="Minimum 8 characters, one number, one uppercase and one lowercase letter" required pattern="(?=^.{8,}$)(?=.*'d)(?=.*[a-z])(?=.*[A-Z])(?!.*'s)[0-9a-zA-Z!@#$%^&*()]*$" />
<table>
<tr>
<h4> Birth day</h4>
</tr>
<tr>
<td>
<asp:DropDownList ID="dayReg" runat="server" cssClass="form-control" >
<asp:ListItem Selected="True" Value="Invalid">Day</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="monthReg" runat="server" cssClass="form-control" onchange="popDayReg()" >
<asp:ListItem Selected="True" Value="1">1</asp:ListItem>
<asp:ListItem Selected="False" Value="2">2</asp:ListItem>
<asp:ListItem Selected="False" Value="3">3</asp:ListItem>
<asp:ListItem Selected="False" Value="4">4</asp:ListItem>
<asp:ListItem Selected="False" Value="5">5</asp:ListItem>
<asp:ListItem Selected="False" Value="6">6</asp:ListItem>
<asp:ListItem Selected="False" Value="7">7</asp:ListItem>
<asp:ListItem Selected="False" Value="8">8</asp:ListItem>
<asp:ListItem Selected="False" Value="9">9</asp:ListItem>
<asp:ListItem Selected="False" Value="10">10</asp:ListItem>
<asp:ListItem Selected="False" Value="11">11</asp:ListItem>
<asp:ListItem Selected="False" Value="12">12</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="yearReg" runat="server" cssClass="form-control" onchange="popDayReg()">
<asp:ListItem Selected="True" Value="Invalid">Year</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
<label class="checkbox-inline"><input runat="server" type="radio" name="sexReg" id="maleReg" value="male" checked="true" />Male</label>
<label class="checkbox-inline"><input type="radio" name="sexReg" id="femaleReg" value="female"/>Female</label>
<br /><asp:Button runat="server" class="btn btn-success"
text="Register" ID="RegisterButton" ValidationGroup="Register" onclick="RegisterButton_Click" />
</td>
<td>
<div><img alt="Image did not load :(" class="style1" src="../Images/bbingguy.jpg" /></div>
</td>
</tr>
<tr><td><label runat="server" id="failedRegister">Oh no, something went wrong with your registration. Please try again</label></td></tr>
</table>
<!--</form>-->
</form>
</body>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Login_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void SignInButton_Click(object sender, EventArgs e)
{
//runs
}
protected void RegisterButton_Click(object sender, EventArgs e)
{
//does not run
}
}
我的问题是,第一个提交按钮(登录按钮)导致它的C#函数运行,但第二个提交按钮不运行(注册按钮),有人知道为什么吗?
编辑:两个按钮都会导致回发,但第二个按钮没有运行它的功能,我可以清理代码,但我担心它会删除问题的根源,因为我是网站建设等方面的新手。
表单标记中有多个Form标记。表单标记不能嵌套在表单标记中。一个页面中可以有多个HTML表单标记,但它们不能嵌套在一起。
因此,删除嵌套的表单标记,只使用一个表单标记制作页面。那么就很好
删除此处提到的两个表单标签
您的最终代码将是,在删除嵌套的表单标签并实现验证组之后
<body>
<form id="form1" runat="server">
<div class="jumbotron">
<h1>Welcome to BodySpace</h1>
<div class="navbar-collapse collapse">
<table>
<tr>
<td>
<asp:TextBox type="email" runat="server" name="email" ID="email" class="input-block-level" ValidationGroup="SignIn" placeholder="Email" required /></td>
<td>
<input type="password" runat="server" name="pass" id="pass" class="input-block-level" ValidationGroup="SignIn" placeholder="Password" required /></td>
<td>
<asp:Button type="submit" runat="server" class="btn btn-success" Text="Sign-In" ID="SignInButton" ValidationGroup="SignIn" OnClick="SignInButton_Click" /></td>
<td>
<label runat="server" id="failedLogin">Incorrect email and password combination</label></td>
</tr>
<tr>
<td></td>
<td></td>
<td><a class="btn btn-block btn-social btn-facebook"><i class="fa fa-facebook"></i>Sign in with Facebook</a></td>
</tr>
</table>
</div>
</div>
<table>
<tr>
<td>
<h3>This website and all of it's
</h3>
<h3>contents are and will remain free</h3>
<table>
<tr>
<td>
<input runat="server" type="text" name="fNameReg" id="fNameReg" class="form-control" placeholder="First name" required /></td>
<td>
<input type="text" runat="server" name="lNameReg" id="lNameReg" class="form-control" placeholder="Last name" required /></td>
</tr>
</table>
<br />
<asp:TextBox runat="server" type="email" name="emailReg" ID="emailReg" class="form-control" placeholder="Your email adress" title="Must be a valid email adress" required pattern="^[0-9a-zA-Z]+([0-9a-zA-Z]*[-._+])*[0-9a-zA-Z]+@[0-9a-zA-Z]+([-.][0-9a-zA-Z]+)*([0-9a-zA-Z]*[.])[a-zA-Z]{2,6}$" />
<br />
<input runat="server" type="text" name="emailRegCheck" id="emailRegCheck" class="form-control" placeholder="Retype your email adress" required />
<br />
<input runat="server" type="password" name="passwordReg" id="passwordReg" class="form-control" placeholder="Password" title="Minimum 8 characters, one number, one uppercase and one lowercase letter" required pattern="(?=^.{8,}$)(?=.*'d)(?=.*[a-z])(?=.*[A-Z])(?!.*'s)[0-9a-zA-Z!@#$%^&*()]*$" />
<table>
<tr>
<h4>Birth day</h4>
</tr>
<tr>
<td> <asp:DropDownList ID="dayReg" runat="server" CssClass="form-control">
<asp:ListItem Selected="True" Value="Invalid">Day</asp:ListItem>
</asp:DropDownList>
</td>
<td> <asp:DropDownList ID="monthReg" runat="server" CssClass="form-control" onchange="popDayReg()">
<asp:ListItem Selected="True" Value="1">1</asp:ListItem>
<asp:ListItem Selected="False" Value="2">2</asp:ListItem>
<asp:ListItem Selected="False" Value="3">3</asp:ListItem>
<asp:ListItem Selected="False" Value="4">4</asp:ListItem>
<asp:ListItem Selected="False" Value="5">5</asp:ListItem>
<asp:ListItem Selected="False" Value="6">6</asp:ListItem>
<asp:ListItem Selected="False" Value="7">7</asp:ListItem>
<asp:ListItem Selected="False" Value="8">8</asp:ListItem>
<asp:ListItem Selected="False" Value="9">9</asp:ListItem>
<asp:ListItem Selected="False" Value="10">10</asp:ListItem>
<asp:ListItem Selected="False" Value="11">11</asp:ListItem>
<asp:ListItem Selected="False" Value="12">12</asp:ListItem>
</asp:DropDownList>
</td>
<td> <asp:DropDownList ID="yearReg" runat="server" CssClass="form-control" onchange="popDayReg()">
<asp:ListItem Selected="True" Value="Invalid">Year</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
<label class="checkbox-inline">
<input runat="server" type="radio" name="sexReg" id="maleReg" value="male" />Male</label>
<label class="checkbox-inline">
<input type="radio" name="sexReg" id="femaleReg" value="female" />Female</label>
<br />
<asp:Button runat="server" type="submit" class="btn btn-success"
Text="Register" ID="RegisterButton" OnClick="RegisterButton_Click" />
</td>
<td>
<div>
<img alt="Image did not load :(" class="style1" src="../Images/bbingguy.jpg" /></div>
</td>
</tr>
<tr>
<td>
<label runat="server" id="failedRegister">Oh no, something went wrong with your registration. Please try again</label></td>
</tr>
</table>
</form>
</body>