Application does not show javascript message when using UPDATE PANEL

I am making an ASP.NET application (C #). [Visual Studio 2010]

In the case when I try to use a client-side message using javascript, it shows me a message when the update panel is not in use.

But as soon as I added the update panel to my application to prevent it from posting back, it will not show me such a javascript message when inserting a record.

In the following example, I am trying to display a message:

Response.Write("<head><script type='text/javascript'>alert('Member Registered Sucessfully')</script></head>"); 

My code is:

  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 I am doing the workshop.

I beg you, please.

+4
source share
1 answer

If you have an update panel, use ScriptManager.RegisterClientScriptBlock , as shown below

 ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('Member Registered Sucessfully');", true) 

You cannot use Response.Write during asynchronous postback.

+8
source

Source: https://habr.com/ru/post/1481322/


All Articles