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)
@freelancer If you are using ScriptManager then try this code for message..
string script = "alert(\"Hello!\");";
ScriptManager.RegisterStartupScript(this, GetType(),
"ServerControlScript", script, true);
Make a method of MsgBox in your page.
public void MsgBox(String ex, Page pg,Object obj)
{
string s = "<SCRIPT language='javascript'>alert('" + ex.Replace("\r\n", "\\n").Replace("'", "") + "'); </SCRIPT>";
Type cstype = obj.GetType();
ClientScriptManager cs = pg.ClientScript;
cs.RegisterClientScriptBlock(cstype, s, s.ToString());
}
and when you want to use msgbox just put this line
MsgBox("! your message !", this.Page, this);
just try this, it works fine in my browser:
your response writing code should be
Response.Write("<script>alert('login successful');</script>");
Hope this works
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With