I am generating a button by code (I generate a button to delete, there is a button for each row of a dynamic table) and I need to generate an alert to prevent them from deleting information by mistake.
Button boton = new Button();
boton.Text = "Eliminar";
boton.Click += new EventHandler(encontrarEliminar);
private void encontrarEliminar(object sender, EventArgs e){
. . . CODIGO . . .
}
I found that the best way to use a confirm is through javascript. Here is the javascript code:
function Confirm() {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm("Seguro que quieres eliminar?")) {
confirm_value.value = "Yes";
} else {
confirm_value.value = "No";
}
document.forms[0].appendChild(confirm_value);
}
And it is assumed that the button would have to work correctly in this way:
<asp:Button ID="btnConfirm" runat="server" OnClick = "encontrarEliminar()" Text = "Raise Confirm" OnClientClick = "Confirm()"/>
The problem here is that you can only assign the button an event EventHandler type would like to know if there is any way to assign the javascript method or if there is another way to confirm.