在ASP验证失败之后,即使我提供了正确的输入,也无法仅第一次调用服务方法 [英] Right after ASP validation fails, I cannot invoke the service method ONLY first time even if I provide the correct input

查看:88
本文介绍了在ASP验证失败之后,即使我提供了正确的输入,也无法仅第一次调用服务方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有ASP验证的小表格。
验证失败并输入错误后,我提供正确的输入并按一个按钮。仍然显示 * 表示没有任何错误。但是,当第二次按下按钮时,将调用该服务。

I have a small form with asp validations. After validation fails with the wrong input, I provide the correct input and press a button. Nothing happens with * still displayed indicating an error. However, when pressing button second time, the service is called.

这是提供错误Bin的第一种情况:

This is the first scenario when providing the wrong Bin:

这是第二种情况:

当输入正确并按搜索按钮时,将导致服务方法调用,但确实如此什么也没做。只有在我再次按下搜索后,它才调用服务

When the input is correct and pressing "Search" button should cause the service method call, but it does not do anything. Only after I press on "Search" again it calls the service

这是我的验证器,并带有以下按钮:

This is my validators with the button:

   <span style="position:relative">
        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" CssClass="searchValidator"  ErrorMessage="Bin is missing" ControlToValidate="txtIssuerSearch" ForeColor="Red" ValidationGroup="vgIssuerSearch">*</asp:RequiredFieldValidator>
        <asp:RegularExpressionValidator ID="RegularExpressionValidatorIssuerSearch" runat="server" CssClass="searchValidator" ErrorMessage="Invalid Bin Entered" ControlToValidate="txtIssuerSearch" ForeColor="Red" ValidationGroup="vgIssuerSearch" ValidationExpression="^([0-9]{6}|[0-9]{8})$">*</asp:RegularExpressionValidator>
   </span> 
       <asp:TextBox ID="txtIssuerSearch" runat="server"></asp:TextBox>
<asp:DropDownList ID="ddlIssuerSearch" runat="server">
<asp:ListItem>Name</asp:ListItem>
<asp:ListItem>Bin</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btnIssuerSearch" runat="server" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" 
    CausesValidation="false" CommandName="Search" Text="Search" OnCommand="btnIssuerSearch_Click" OnClientClick="return ValidateOnSearch()" />

这是我的javascript函数:

and this is my javascript function:

function ValidateOnSearch() {

var isValid = false;
var ddlValue = $('#cphBody_ddlIssuerSearch :selected').text();

if (ddlValue == 'Name') {
    isValid = true;
}
else {
    isValid = Page_ClientValidate('vgIssuerSearch');
 }

if (!isValid) {
    $("#errorDisplaySearch").dialog({
        title: "Validation Error",
        modal: true,
        resizable: false,
        width: 250,
        buttons: {
            Close: function () {
                $(this).dialog('close');
            }
        }
    });
    return false;
}
return true;
}

我错过了什么?

推荐答案

我认为您需要在下拉列表中选择名称值时禁用RegularExpressionValidator。

I think you need to disable the RegularExpressionValidator when the Name value is selected in the dropdown.

添加onchange事件下拉式处理程序:

Add onchange event handler on dropdown:

<asp:DropDownList ID="ddlIssuerSearch" runat="server" onchange="updateValidatorStatus(this.value)">

    updateValidatorStatus(selectedVal) {

    var regExpVal = document.getElementById('<%=RegularExpressionValidatorIssuerSearch.ClientID%>');

    if (selectedVal === 'Name') {
        ValidatorEnable(regExpVal, false);
    } else {
        ValidatorEnable(regExpVal, true);
    }
}

这篇关于在ASP验证失败之后,即使我提供了正确的输入,也无法仅第一次调用服务方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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