gpt4 book ai didi

asp.net - RequiredFieldValidator 在隐藏时仍然进行验证

转载 作者:行者123 更新时间:2023-12-02 00:11:46 27 4
gpt4 key购买 nike

我有 2 个字段需要验证,如果它们显示在屏幕上。当表单最初加载时,它们是隐藏的,除非从 DropDown 框中选择了一个项目,否则它们将保持隐藏状态。选择值后,将出现 2 个字段,然后验证工作正常。但是,如果选择了另一个不会使这 2 个字段出现的值,则它们仍在验证中并且不允许页面提交。关于如何实现这一目标的任何想法?

function DisplayOutageDates() {
if ($('#ddImpact').val() == "Service Affecting") {
$('#outageDates').css('display','');
document.getElementById('txtOutageStartDate').Visible = true;
document.getElementById('RFVOutageStartDate').Visible = true;
} else {
$('#outageDates').css('display','none');
document.getElementById('txtOutageStartDate').Visible = false;
document.getElementById('RFVOutageStartDate').Visible = false;
}
}

<asp:RequiredFieldValidator ID="RFVOutageStartDate" runat="server"
ControlToValidate="txtOutageStartDate" SetFocusOnError="true"
ErrorMessage="Please enter the Outage Start Date" />

最佳答案

你可以使用:

ValidatorEnable(val, enable): 
Takes a client-validator and a Boolean value.
Enables or disables a client validator.
Being disabled will stop it from evaluating and it will always appear valid.

发现于 msdn .

使用 Javascript 这看起来像:

ValidatorEnable(document.getElementById('<%=Validator1.ClientID%>'), state);
//where state would be a boolean

在 JQuery 中,这看起来像:

 ValidatorEnable($("#<%= Validator1.ClientID %>")[0], state);

如下所示: http://codeclimber.net.nz/archive/2008/05/14/how-to-manage-asp.net-validation-from-javascript-with-jquery.aspx

关于asp.net - RequiredFieldValidator 在隐藏时仍然进行验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14873250/

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