的RequiredFieldValidator需要用户点击两次 [英] RequiredFieldValidator requires user to click twice

查看:228
本文介绍了的RequiredFieldValidator需要用户点击两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框,一个简单的Web表单和一个RequiredFieldValidator连接到它。当的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" />

我尝试添加的CausesValidation 来从每一个谷歌搜索找到一个建议的文本框,它并不能帮助。

I tried adding CausesValidation to the textbox per a suggestion found from a Google search and it doesn't help.

修改看来,它并不总是必须是双击断火的事件。只要文本输入到文本框,然后将焦点从文本框中带走的的RequiredFieldValidator错误信息消失和形式,只需要一个单一的点击。

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.

推荐答案

这是因为code,它清除出来的错误信息时,文本框失去焦点运行。那么,什么情况是:

This happens because the code that clears out the error message runs when the textbox loses focus. So what happens is:


  1. 您在字段中输入文本

  2. 您按一下按钮,这将导致onblur事件的文本框的情况发生,发射了code,再次检查该字段的值并删除错误信息

  3. 现在,还有的验证没有任何错误,那么单击按钮再次提交表单。

在preSS tab键第一个(或基本做任何把焦点离开文本框),这样当您单击提交按钮,它已经准备就绪,那么的onblur脚本运行并清除出错误

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.

这篇关于的RequiredFieldValidator需要用户点击两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆