Asp.net - manually run client-side verification code from another event

I want to run any client-side validation procedure connected to a specific text input element.

The check was installed using CustomValidator:

<asp:textbox id="AddEstTime" runat="server" Width="55px"></asp:textbox><br />
<asp:CustomValidator ID="AddEstTimeCustomValidator" ClientValidationFunction="AddEstTimeCustomValidator_ClientValidate" OnServerValidate="AddEstTimeCustomValidator_ServerValidate" ErrorMessage="Please enter a time" ControlToValidate="AddEstTime"  runat="server" Display="Dynamic" ValidateEmptyText="true"/>
<asp:CheckBox ID="AddIsTM" runat="server" Text="T&amp;M" />

and javascript:

function AddEstTimeCustomValidator_ClientValidate(sender, args) {
    var checkbox = $("input[id$='IsTM']");
    args.IsValid = checkbox.is(":checked") || args.Value.match(/^\d+$/);
}

When the state of CheckBox"AddIsTM" changes , I want to re-check textbox"AddEstTime" using its connected CustomValidator"AddEstTimeCustomValidator".

I know about focus → add character reorientation → delete character. I am trying to find a more correct way. New in asp.NET.

+5
source share
3 answers

After looking at the Microsoft client side code, I came to the following:

// client-side validation of one user-control.
// pass in jquery object with the validation control
function ValidateOneElement(passedValidator) {
    if (typeof (Page_Validators) == "undefined") {
        return;
    }
    $.each(Page_Validators, function (index, value) {
        if ($(value).attr("id") == passedValidator.attr("id")) {
            ValidatorValidate(value, null, null);
        }
    });
}

Page_ClientValidate:

function Page_ClientValidate(validationGroup) {
    Page_InvalidControlToBeFocused = null;
    if (typeof(Page_Validators) == "undefined") {
        return true;
    }
    var i;
    for (i = 0; i < Page_Validators.length; i++) {
        ValidatorValidate(Page_Validators[i], validationGroup, null);
    }
    ValidatorUpdateIsValid();
    ValidationSummaryOnSubmit(validationGroup);
    Page_BlockSubmit = !Page_IsValid;
    return Page_IsValid;
}
+3

sennett ()

JS

Page_ClientValidate();

,

Page_ClientValidate("validationGroupName")
+3

ASP.NET, , , , . - jQuery ( ), .

+1

All Articles