requiredFieldValidator 要求用户单击两次
我有一个简单的网络表单,其中有一个文本框和一个连接到它的RequiredFieldValidator。当触发RequiredFieldValidator错误时,用户必须单击提交两次才能发布表单。第一次单击会清除错误,第二次单击实际上会触发按钮单击事件。这是预期的行为吗?
<asp:RequiredFieldValidator ID="reqFieldCloseComment" ControlToValidate="tbCloseComment" ValidationGroup="ChangeStatus" ErrorMessage="Please enter a reason" Display="Dynamic" runat="server"></asp:RequiredFieldValidator>
<asp:TextBox ID="tbCloseComment" runat="server" CausesValidation="true" TextMode="MultiLine" Height="107px" Width="400px"></asp:TextBox>
<asp:Button ID="btnCloseRequestFinal" Text="Finish" CssClass="CloseReqButton" runat="server" ValidationGroup="ChangeStatus" />
我尝试根据 Google 搜索中找到的建议将 CausesValidation
添加到文本框,但没有帮助。
编辑似乎并不总是需要双击才能触发事件。只要在文本框中输入文本,然后将焦点从文本框中移开,RequiredFieldValidator 错误消息就会消失,并且表单只需单击一下即可。
I have a simple web form with a textbox and a RequiredFieldValidator wired up to it. When the RequiredFieldValidator error is triggered the user has to click the submit twice to post the form. The first click clears the error, the second actually fires off the button click event. Is this expected behavior?
<asp:RequiredFieldValidator ID="reqFieldCloseComment" ControlToValidate="tbCloseComment" ValidationGroup="ChangeStatus" ErrorMessage="Please enter a reason" Display="Dynamic" runat="server"></asp:RequiredFieldValidator>
<asp:TextBox ID="tbCloseComment" runat="server" CausesValidation="true" TextMode="MultiLine" Height="107px" Width="400px"></asp:TextBox>
<asp:Button ID="btnCloseRequestFinal" Text="Finish" CssClass="CloseReqButton" runat="server" ValidationGroup="ChangeStatus" />
I tried adding CausesValidation
to the textbox per a suggestion found from a Google search and it doesn't help.
EDIT It seems that it doesn't always have to be a double click to fire off the event. As long as text is entered into the textbox and then the focus is taken away from the textbox, the RequiredFieldValidator error message goes away and the form requires only a single click.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在使用
CompareValidator
时遇到了同样的问题,当我将Display
属性从动态更改为静态。希望有帮助I had the same issue with a
CompareValidator
and found the problem went away when I changed theDisplay
property from Dynamic to Static. Hope that helps发生这种情况是因为当文本框失去焦点时会运行清除错误消息的代码。那么发生的情况是:
当您先按 Tab 键(或者基本上执行任何使焦点离开文本框的操作)时,onblur 脚本就会运行并清除错误,以便当您单击提交按钮时,它就可以开始了。
This happens because the code that clears out the error message runs when the textbox loses focus. So what happens is:
When you press the tab key first (or basically do anything that takes the focus off the textbox), then that onblur script runs and clears out the error so that when you click the submit button it is ready to go.