Crear mensaje emergente con sweetalert2

 Para el ejemplo crearemos un mensaje de alerta muy vistoso con la librería Sweetalert2, crearemos una Webforms.

llamaremos la librería:

https://cdn.jsdelivr.net/npm/sweetalert2@11

y un botón llamado btnAlerta.


<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

     <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

</head>

<body>

    <form id="form1" runat="server">

        <div>

            <asp:Button ID="btnAlerta" runat="server" Text="Mostrar Alerta" OnClick="btnAlerta_Click" />

        </div>

    </form>

</body>

</html>

Dentro del código de botón:


    Protected Sub btnAlerta_Click(sender As Object, e As EventArgs) Handles btnAlerta.Click
        Dim script As String = "Swal.fire({
        title: '¡Registro grabado!',
        text: 'Avise al administrador',
        icon: 'success',
        confirmButtonText: 'Aceptar'
        });"
        ClientScript.RegisterStartupScript(Me.GetType(), "SweetAlert", script, True)
    End Sub

Podemos cambiar el icono dependiendo el tipo de mensaje.

icon: 'success',  icon: 'error',  icon: 'warning', icon: 'info', icon: 'question

Ejecutamos la forma y presionamos el botón.



Publicar un comentario

0 Comentarios