How to show alert box in asp.net

asp.net

Solution

That's not the way to send javascript code to client on ASP.NET

You could use `Page.ClientScript.RegisterStartupScript`

 Page.ClientScript.RegisterStartupScript(
   this, 
   GetType(), 
   "ALERT", 
   "alert('Selected items are removed successfully')", 
   true);

In this case, you could also use `Page.ClientScript.RegisterClientScriptBlock`

 Page.ClientScript.RegisterClientScriptBlock(
   this, 
   GetType(), 
   "ALERT", 
   "alert('Selected items are removed successfully')", 
   true);

To understand differences between `RegisterStartupScript` and `RegisterClientScriptBlock` you could check here

Difference between RegisterStartupScript and RegisterClientScriptBlock?

You will also understand why they aren't always interchangeable.

Problem

I am showing alert box in my page, but after that my page is breaking down. ``` Response.Write("<script>alert('Selected items are removed successfully')</script>"); ``` How to fix that?

Original source

Related problems