gpt4 book ai didi

asp.net - 占用空间的必需和正则表达式验证

转载 作者:行者123 更新时间:2023-12-04 22:13:30 25 4
gpt4 key购买 nike

我遇到了 asp.net 的字段验证器在我的页面上占用空间的问题。我四处搜索,文档说使用 Display="Dynamic"来防止验证器占用空间。但是,当我使用它时,总是会显示错误消息。

我究竟做错了什么?

我只希望在用户单击“保存”按钮或失去对文本框的关注时显示错误消息。而且我不希望验证器占用空间。

     <p>Please enter a new email:</p> 
<asp:TextBox runat="server" MaxLength="255" ID="TextBoxEmail" />

<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
ValidationGgroup="Email"
ErrorMessage="Please enter an email"
ControlToValidate="TextBoxEmail" runat="server"></asp:RequiredFieldValidator>

<asp:RegularExpressionValidator ID="RegularExpressionValidator2"
ValidationGroup="Email"
ControlToValidate="TextBoxEmail"
ErrorMessage="Please enter valid email"
runat="server"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" />


<p>Please re-enter your email:</p>
<asp:TextBox runat="server" ID="TextBoxEmail2" />


<asp:LinkButton ValidationGroup="Email" runat="server" Text="Save" OnClick="linkbuttonSave_Click" />

最佳答案

我在你的代码中唯一注意到的是你在 ValidationGgroup="Email" 中有一个错字.应该是 ValidationGroup="Email"
除此之外,Display="Dynamic"为我工作。

enter image description here

点击后,提交按钮 -

enter image description here

<p>
Please enter a new email:</p>
<asp:TextBox runat="server" MaxLength="255" ID="TextBoxEmail" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ValidationGroup="Email"
ErrorMessage="Please enter an email" ControlToValidate="TextBoxEmail" runat="server"
Display="Dynamic"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" ValidationGroup="Email"
ControlToValidate="TextBoxEmail" ErrorMessage="Please enter valid email" runat="server"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" Display="Dynamic" />
<p>
Please re-enter your email:</p>
<asp:TextBox runat="server" ID="TextBoxEmail2" />
<asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="TextBoxEmail"
ControlToValidate="TextBoxEmail2" CssClass="failureNotification" Display="Dynamic"
ErrorMessage="Must match." ValidationGroup="Email"></asp:CompareValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" ValidationGroup="Email"
ErrorMessage="Please enter an confirm email" ControlToValidate="TextBoxEmail2" runat="server"
Display="Dynamic"></asp:RequiredFieldValidator>
<asp:LinkButton ID="LinkButton1" ValidationGroup="Email" runat="server" Text="Save"
OnClick="linkbuttonSave_Click" />

关于asp.net - 占用空间的必需和正则表达式验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16308660/

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