Add client side javascript code and ASP.Net validation on a asp.net button

Posted by Vinni on Stack Overflow See other posts from Stack Overflow or by Vinni
Published on 2010-04-19T10:29:44Z Indexed on 2010/04/19 10:33 UTC
Read the original article Hit count: 338

Filed under:
|
|

Hello guys, 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]);
        }

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about html