0

I wanted to write javascript code on "OnClientClick" of the asp.net button and also I want the asp.net validation to be run for that button. but when i mix these both validation is not working. please help me out. Below is my code

ASPX

<asp:Button ID="btnAddToFeatureOffers" runat="server" Text="Add to Feature Offers"
                                                OnClick="btnAddToFeatureOffers_Click" ValidationGroup="vgAddOffer" OnClientClick="add();" />

javascript

 function add() {
            var selectedOrder = $('#ctl00_MainContent_ddlFeaturedHostingType option:selected')[0].index;
            var offer = $('#<%=txtOrder.ClientID%>').val();
            var a = $("<a>").attr("href", "#").addClass("offer").text("X");
            $("<div>").text(offer).append(a).appendTo($('#resultTable #resultRow td')[selectedOrder - 1]);
        }

1 Answer 1

1

Try giving a return false or return true inside the function add based on your validation result.

Also no need to write selector like this

$('#resultTable #resultRow td')

Simply write

$('#resultRow td')
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.