I am making ASP.NET application (C#). [Visual Studio 2010]
In that when i try to use client side message using javascript, it shows me message when update panel is not used.
But as soon as i added update panel to my application for preventing it from postback, Its not showing me such javascript message on insertion of record.
In the following way i am trying to display message:
Response.Write("<head><script type='text/javascript'>alert('Member Registered Sucessfully')</script></head>");
My Code:
 try
{
    con.Open();
    cmd = new SqlCommand("insert into register values(@name,@city,@address,@mobile)",con);
    cmd.Parameters.AddWithValue("@name",txtName.Text);
    cmd.Parameters.AddWithValue("@city", ddlCity.Text);
    cmd.Parameters.AddWithValue("@address",txtAddress.Text);
    cmd.Parameters.AddWithValue("@mobile", txtMobile.Text);
    da = new SqlDataAdapter(cmd);
    ds = new DataSet();
    da.Fill(ds);
    int res=cmd.ExecuteNonQuery();
    if (res > 0)
    {
        Response.Write("<head><script type='text/javascript'>alert('Member Registered Sucessfully')</script></head>");
    }
    else
    {
        Response.Write("<head><script type='text/javascript'>alert('Member Not Registered Sucessfully')</script></head>");
    }
    con.Close();
}
Please tell me where am i making mastake.
Please guide me.
If you have update panel use ScriptManager.RegisterClientScriptBlock as below 
ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('Member Registered Sucessfully');", true)
You can't use Response.Write during an asynchronous postback.
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