How to send an alert ("") from asp.net, sending a string + a variable

1

In what way you should send a message type alert, from an asp.net form.

Currently I used this:

            if (user._contraseña.Equals(claveI))
            {

                ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Bienvenido: ');", true);

            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Clave incorrecta');", true);
                txtContraseña.Text = "";
            }

but this only allows me to send a string, if I want to add an extra variable, it does not send any alert.

                if (user._contraseña.Equals(claveI))
                {
                String nombre = user.nombreCompleto();
                    ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Bienvenido: ');"+nombre, true);

                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Clave incorrecta');", true);
                    txtContraseña.Text = "";
                }
    
asked by Javier Gallardo 11.11.2018 в 01:24
source

1 answer

1

You are not joining the name to the message, use something like this:

string script = string.Format("alert('Bienvenido:{0}');", nombre);
ClientScript.RegisterStartupScript(this.GetType(), "alert", script, true);

There you will see that in the position {0} the name will be added

    
answered by 11.11.2018 / 01:28
source