我仍在为学校项目学习 ASP.NET。我有一个页面,上面有 2 个字段集。一个填写登录表单(自制,我不使用asp登录控件),另一个填写一个按钮,进入注册页面。该按钮有效,您会被重定向到注册页面,但它会在链接之前显示未填写的登录表单的错误消息半秒。我想知道是否有办法阻止这种情况发生。这是我的代码,我没有在后面的代码中添加任何东西,所以我不会发布。
<%-- Begin fieldset --%>
<fieldset>
<legend>Log in Form</legend>
<ol>
<li>
<%-- Email label, textbox en validator --%>
<asp:Label ID="Label2" runat="server" AssociatedControlID="Email">Email: </asp:Label>
<asp:TextBox runat="server" ID="Email" TextMode="Email" />
<%-- Validator om te zien of het veld is ingevuld --%>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="Email"
CssClass="field-validation-error" ErrorMessage="Email is een verplicht veld!" />
<asp:RegularExpressionValidator ID="RegularExpressionValidatorEmail" runat="server"
ControlToValidate="Email" CssClass="field-validation-error" Display="Dynamic"
ValidationExpression="^((?>[a-zA-Z\d!#$%&'*+\-/=?^_`{|}~]+\x20*|((?=[\x01-\x7f])[^\\]|\\[\x01-\x7f])*\x20*)*(?<angle><))?((?!\.)(?>\.?[a-zA-Z\d!#$%&'*+\-/=?^_`{|}~]+)+|((?=[\x01-\x7f])[^\\]|\\[\x01-\x7f])*)@(((?!-)[a-zA-Z\d\-]+(?<!-)\.)+[a-zA-Z]{2,}|\[(((?(?<!\[)\.)(25[0-5]|2[0-4]\d|[01]?\d?\d)){4}|[a-zA-Z\d\-]*[a-zA-Z\d]:((?=[\x01-\x7f])[^\\\[\]]|\\[\x01-\x7f])+)\])(?(angle)>)$"
ErrorMessage="Gebruik geen illegale tekens in uw email aub!"></asp:RegularExpressionValidator>
</li>
<li>
<%-- Passwoord label en textbox --%>
<asp:Label ID="Label3" runat="server" AssociatedControlID="Password">Wachtwoord: </asp:Label>
<asp:TextBox runat="server" ID="Password" TextMode="Password" />
<%-- Validator om te zien of het veld is ingevuld--%>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="Password"
CssClass="field-validation-error" ErrorMessage="Wachtwoord is een verplicht veld!" />
</li>
</ol>
<%-- Registreer button --%>
<asp:Button ID="buttonLogIn" runat="server" CommandName="MoveNext" Text="Log in" />
</fieldset>
<%-- Einde fieldset --%>
<%-- Begin fieldset --%>
<fieldset>
<legend>Registreer hier!</legend>
<%-- Registreer button --%>
<asp:Button ID="buttonRegistreerHier" runat="server" CommandName="MoveNext" Text="Registreer hier!!"
OnClick="buttonRegistreerHier_Click" OnClientClick="window.location.href='RegistratieForm.aspx'"
PostBackUrl="~/RegistratieForm.aspx" />
</fieldset>
<%-- Einde fieldset --%>
这是我单击按钮并显示错误消息的那一刻的图像,它只需要半秒到 1 秒,但很麻烦。