如何获取在C#的js中按下的按钮

时间:2019-06-11 16:27:29

标签: javascript c# sweetalert2

您好,您能帮我检测一下警报消息框上按下了哪个按钮吗,这是我的代码

js代码:

<script>
function alertt() {
    Swal.fire({
        title: 'Seguro que desea eliminar el registro?',
        text: "esta accion no se puede revertir",
        type: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'si, eliminar'
    }).then((result) => {
        if (result.value) {
            Swal.fire(
              'Eliminaro',
              'El registro ha sido eliminado',
              'success'
            )
        }
    })
}
</script>
...
<asp:Button ID="BtnEliminartel" runat="server" class="btn btn-primary" Text="Eliminar" Style="float:right" OnClick="BtnEliminartelClick"/>
<--!This is the button who calls the method Eliminar-->

所有这些代码都在.aspx文件中

此代码位于c#文件的后面

protected void BtnEliminartelClick(object sender, EventArgs e)
    {

        ClientScript.RegisterStartupScript(this.GetType(), "randomtrxt", "alertt()", true); //This line shows the alert message box
        try
        {
            SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog = GMG; Trusted_Connection = true; ");

            con.Open();
            SqlCommand com = new SqlCommand(); // Create a object of SqlCommand class
            com.Connection = con; //Pass the connection object to Command
            com.CommandType = CommandType.Text;
            com.CommandText = "DELETE FROM TELEFONOS WHERE TEL_NUMERO_TELEFONO = '" + txttelAux.Text + "' ";
            com.ExecuteNonQuery();
            DdTelefonos.ClearSelection();
            txtRegRecNumeroTel.Text = "";
        }
        catch (SqlException ex)
        {
            //errror exception

        }
        cargarTelefonos();
    }   

我希望当用户在警报消息框中选择“ confirm”按钮时,寄存器将消除,而当选择其他选项时,不要删除该寄存器,但是在两种情况下,我的代码会删除该寄存器,或者还有另一种方法? / p>

0 个答案:

没有答案