开发者

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

开发者 https://www.devze.com 2022-12-27 03:39 出处:网络
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. plea

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="vgAddOff开发者_如何转开发er" 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]);
        }


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')
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号