Add client side javascript code and ASP.Net validation on a asp.net button
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')
精彩评论