Search code examples
javascriptc#asp.net

How can I display a messagebox in ASP.NET?


I want to show a message box on the successful save of any item. I googled it and tried different solutions, but none of them worked. Here is the code I am using:

try
{
    con.Open();
    string pass="abc";
    cmd = new SqlCommand("insert into register values('" + 
                                       txtName.Text + "','" + 
                                       txtEmail.Text + "','" + 
                                       txtPhoneNumber.Text + "','" + 
                                       ddlUserType.SelectedText + "','" + 
                                       pass + "')", con);

    cmd.ExecuteNonQuery();
    con.Close();
    Response.Write("<script LANGUAGE='JavaScript' >alert('Login Successful')</script>");
}
catch (Exception ex)
{

}
finally
{
    con.Close();
}

(I am using Firefox, if that matters)


Solution

  • @freelancer If you are using ScriptManager then try this code for message..

    string script = "alert(\"Hello!\");";
    ScriptManager.RegisterStartupScript(this, GetType(), 
                          "ServerControlScript", script, true);