Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to set my custom error messages using ClientValidationFunction in javascript.The error messages shows up properly in IE8 but not in IE9 and chrome
My Validator
ASP.NET
<asp:CustomValidator runat="server"  EnableClientScript="true" ID="cvLogMsg" ClientValidationFunction="user"></asp:CustomValidator>


Javascript function
JavaScript
function user(source, args) {
               var bool = false;
            var errorMessage = '';
            var oldpass = $find('txtOldPassword');
            var currpass = document.getElementById('oldpass');

            var newpass = $find('txtNewPassword');
            var confirmpass = $find('txtConfirmPassword');
            if (oldpass.get_value().length > 0) {
                $('#ELabel1').removeClass('lablelRed');
            }
            if (newpass.get_value().length > 0) {
                $('#ELabel2').removeClass('lablelRed');
            }
            if (confirmpass.get_value().length > 0) {
                $('#ELabel3').removeClass('lablelRed');
            }
            if (oldpass != null && oldpass.get_value().length > 0 || confirmpass != null && confirmpass.get_value().length > 0 || newpass != null && newpass.get_value().length > 0) {
                if (oldpass != null && oldpass.get_value().length == 0) {
                    bool = true;
                    if (document.getElementById('lblCurrentPassMsg') != null && document.getElementById('lblCurrentPassMsg').innerText) {
                        errorMessage = document.getElementById('lblCurrentPassMsg').innerText;
                        $('#ELabel1').addClass('lablelRed');
                    } 
                }
                 else if (confirmpass != null && confirmpass.get_value().length == 0) {
                        bool = true;
                        if (document.getElementById('lblConpassMsg') != null && document.getElementById('lblConpassMsg').innerText) {
                            errorMessage = document.getElementById('lblConpassMsg').innerText;
                            $('#ELabel3').addClass('lablelRed');
                        }
                    }
                }

         
            if (bool == true) {
                
                source.setAttribute("errormessage", errorMessage);
                         
                args.IsValid = false
            }
            else {
                args.IsValid = true
            } 
        }


above set 'errorMessage' doesn't shows up in IE9 and chrome it gives blank message.
Posted

1 solution

Found it myself
source.errormessage = errorMessage;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900