如何重新启用验证控制而不同时执行立即验证?

发布于 2024-08-30 19:18:47 字数 1125 浏览 8 评论 0原文

当我调用此函数以从客户端 javascript 启用验证器时:

`ValidatorEnable(document.getElementById('<%=valPassportOtherText.ClientID%>'), true); //enable`  validation control

所需的验证控件立即执行验证,发现关联文本框中的值为空并将焦点设置到文本框(因为 SetFocusOnError 已设置为 true)。结果,副作用是焦点转移到与验证控件关联的控件,例如 txtSpecifyOccupation。

                          <asp:TextBox ID="txtSpecifyOccupation" runat="server" AutoCompleteType="Disabled"
                                        CssClass="DefaultTextBox DefaultWidth" MaxLength="24" Rows="2"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="valSpecifyOccupation" runat="server" ControlToValidate="txtSpecifyOccupation"
                                        ErrorMessage="1.14b Please specify your &lt;b&gt;Occupation&lt;/b&gt;" 
                                        SetFocusOnError="True">&nbsp;Required</asp:RequiredFieldValidator>

也许有一种方法可以启用(必需的)验证器,而无需同时执行验证(至少在用户关闭它之前?)

我希望 txtSpecifyOccupation 文本框的验证仅在页面提交时或在用户已选择所需的 txtSpecifyocupation 文本框。

我怎样才能实现这个目标?

When I called this function to enable a validator from client javascript:

`ValidatorEnable(document.getElementById('<%=valPassportOtherText.ClientID%>'), true); //enable`  validation control

the required validation control immediately performed it validation, found the value in the associated text box blank and set focus to the textbox (because SetFocusOnError was set to true). As a result, the side effect was that focus was shifted to the control that was associated with the Validation control, i teh example, txtSpecifyOccupation.

                          <asp:TextBox ID="txtSpecifyOccupation" runat="server" AutoCompleteType="Disabled"
                                        CssClass="DefaultTextBox DefaultWidth" MaxLength="24" Rows="2"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="valSpecifyOccupation" runat="server" ControlToValidate="txtSpecifyOccupation"
                                        ErrorMessage="1.14b Please specify your <b>Occupation</b>" 
                                        SetFocusOnError="True"> Required</asp:RequiredFieldValidator>

Perhaps there is a way to enable the (required) validator without having it simultaneously perform the validation (at least until the user has tabbed off of it?)

I'd like validation of the txtSpecifyOccupation textbox to occur only on a Page submit or when the user has tabbed of the required txtSpecifyoccupation textbox.

How can I achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丑丑阿 2024-09-06 19:18:47

不要调用 ValidatorEnable 方法。相反,获取对验证控件的引用并根据需要简单地设置其“启用”属性。

要清除验证控件的错误文本,请将innerText 属性设置为“”。

Don't call the ValidatorEnable method. Instead, get a reference to teh validation control and simply set its "enabled" property as desired.

To clear the validation control's error text, set the innerText property to "".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文