I'm working on a WebForms App based in ASP.NET and coded in C#. This application performs CRUD operations, and I need to show a confirm message to the client every time the user wants to perform an action. I decided to create a jQuery function that receives the title of the window, the message to display to the user and the button that represents the action.
This is my Javascript function:
var _confirm = false;
function Confirm(str, strtitle,button) {
e.preventDefault();
if (!strtitle) strtitle = 'Mensaje de error';
$('#dialog').show();
$('#dialog').html(str);
$("#dialog").dialog({
autoOpen: true,
draggable: false,
resizable: false,
modal: true,
title: strtitle,
width: 350,
height: 180,
show: "slide",
hide: "puff",
buttons: {
"No": function () {
jQuery(this).dialog("close");
},
"Yes": function () {
jQuery(this).dialog("close");
_confirm = true;
button.click();
}
},
close: function () {
jQuery(this).remove();
}
});
return false;
}
This is the ASP Button:
<asp:button id="btnOk" onclick="btnDGV_Click"
onclientclick="Confirm('Desea eliminar el registro', 'Confirmacion', this);"
runat="server" text="Eliminar Registro">
</asp:button>
The code of the event onclick on the server side (it is just a confirm message for the time being):
protected void btnDGV_Click(object sender, EventArgs e) {
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Registro eliminado exitosamente !!!')", true);
}
The issue is that when I click the button the server side message always appears and the jQuery dialog is never shown. What could be the problem?