My asp button uses OnClientClick to execute a javascript function, and I also want to run OnClick after OnClientClick. However, the OnClick never seems to execute. Despite looking through similar topics on StackOverflow and other websites, I can't seem to get it to work for me.
<asp:Button ID="btn_del" runat="server" Font-Bold="True" Text="DELETE" Width="130px" UseSubmitBehavior="false" OnClientClick="if (!RunDelete()) return false;" OnClick="btn_del_Click" />
function RunDelete() {
OnDelete("Delete?", function yes() {
var id = $('#<%=txt_id.ClientID%>').val();
$.ajax({
type: "POST",
url: "/demo.aspx/DeleteRowDb",
data: JSON.stringify({ "RecordID": id }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert(response.d);
}
});
return true;
},
function no() {
return false;
});
}
I've attempted to create another button with the same OnClick behavior and tried to trigger it from JavaScript using
document.getElementById('<%= btn_del2.ClientID %>').click();
, but it still doesn't seem to work.
I really need the OnClick to execute because I rely on the protected void method in the code behind to function correctly, and I'm limited in what I can do within the public static string function.