Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic error message for custom validator clientside

Tags:

I am using a custom validator to call a javascript function for validation. My problem is that I need to be able to change the error message dynamically. Here is the code:

            <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;
            }
        }
    }
like image 543
Mike Avatar asked Mar 22 '11 16:03

Mike


1 Answers

In your validation javascript you can change the message by accessing it via the source:

source.errormessage = "custom message here";

Found this question on SO that should give you some more information as well:

How can I rewrite the ErrorMessage for a CustomValidator control on the client?

like image 63
Kelsey Avatar answered Sep 29 '22 02:09

Kelsey