1

I want to add my error message into the Validation Summary from Javascript instead just alert it. Below is my code for my Javascript.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
        $(document).ready(function () {
            var counter = 0;            

            $("#addrow").on("click", function () {

                var gv = document.getElementById("<%= myTable.ClientID %>");
                var tb = gv.getElementsByTagName("input");

                for (var i = 0; i < tb.length; i++) {
                    if (tb[i].type == "text") {
                        if (tb[i].value < 0.0625) {
                            alert("Dimensions details cannot be empty!");
                            return false;
                        } 
                    }
                }
                return true;                
            });
        });
    </script>



// And I'm using the asp Validation Summary.
   
<asp:ValidationSummary ID="vsSummary" CssClass="errors" runat="server" ValidationGroup="Group1" ForeColor="Red" />

Is it possible to add the error message into the ASP Validation Summary??

Thanks

1 Answer 1

1

You can update html using JavaScript/JQuery.

Check dom, there is available hidden label of validation summary. Update it HTML and make display block.

<script>
$("#vsSummary").html("Dimensions details cannot be empty!");
$("#vsSummary").css("display", "block")

</script>

for hide validation summary you can use fadeOut()

  <script>
            $("#vsSummary").html("Dimensions details cannot be empty!");
            $("#vsSummary").css("display", "block").fadeOut(1000);         
       </script>

If you not get validation summary label, than just add hidden label and update it html and display it. Hope it works in your case.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.