programing

사용자 지정 검증자 클라이언트 측에 대한 동적 오류 메시지

mailnote 2023. 8. 14. 23:03
반응형

사용자 지정 검증자 클라이언트 측에 대한 동적 오류 메시지

나는 검증을 위해 자바스크립트 함수를 호출하기 위해 사용자 정의 검증기를 사용하고 있습니다.제 문제는 오류 메시지를 동적으로 변경할 수 있어야 한다는 것입니다.코드는 다음과 같습니다.

            <asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="fcnValid1"
                ErrorMessage=""  Display="None" ValidateEmptyText="True">
            </asp:CustomValidator>

<asp:ValidationSummary ID="ValidationSummary1" runat="server" DisplayMode="List" ShowMessageBox="True" ShowSummary="False" />

    function fcnValid(source, args) {
        var Status = document.getElementById("<%=ddlStatus.ClientID%>").value

        if (Status == "In Underwriting") {
            if (document.getElementById("<%=txtRequestor.ClientID%>").value == "") {
                //sender.errormessage = "Test1"
                //sender.innerHTML = "Test2";
                document.getElementById("<%=txtRequestor.ClientID%>").focus();
                args.IsValid = false;
            }
        }
    }

유효성 확인 Javascript에서 메시지에 액세스하여 메시지를 변경할 수 있습니다.source:

source.errormessage = "custom message here";

SO에서 다음 질문을 발견했습니다. 자세한 정보도 제공해야 합니다.

클라이언트에서 CustomValidator 컨트롤에 대한 오류 메시지를 다시 작성하려면 어떻게 해야 합니까?

well source.error 메시지가 제대로 작동하지 않았습니다.

source.innerText="오류 메시지"사용하는 것이 좋습니다.

source.errormessage = "custom message here";

언급URL : https://stackoverflow.com/questions/5394861/dynamic-error-message-for-custom-validator-clientside

반응형