I want to call C# code in the code behind from JavaScript ONLY when the validation in the JavaScript is true. I am facing some issues with this can someone help. Thanks Here is my JavaScript
<script type="text/javascript">
function Validate_Checkbox() {
var chks = $("#<%= cblCustomerList.ClientID %> input:checkbox");
var hasChecked = false;
for (var i = 0; i < chks.length; i++) {
if (chks[i].checked) {
hasChecked = true;
//call C# code
break;
}
}
if (hasChecked == false) {
alert("Please select at least one checkbox..!");
return false;
}
return true;
}
</script>
here is the C# code that i want to call
protected void DV_Test_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
do something
}
Here is the button that calls the JavaScript
<asp:Button ID="Button1" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" OnClientClick="javascript:Validate_Checkbox();return true;"/>