Home DotNet How to Raise Javascript Alert in ASP.NET
Author:

Learn how you could raise an alert from ASP.NET code using javascript message box.

We use alert all the time to provide feedback to the website user or to inform them of a process going on in the background. Whatever reason you need to use it for here is a simple solution.

In the code behind we could put the code as follow:

void Page_Load(object sender, EventArgs e)
{
// in this code when the user click on the button a javascript will activated.

btnFeedback.Attributes.Add("onclick", "javascript:alert('Thank you for your feedback.')");
}

If you need to display a message after post back complete then try this:

ClientScript.RegisterStartupScript(this.GetType(), "UpdateCompleteAlert", "alert('The record has been updated.');", true);

Did you like this article?

Another option is to try this:

 

System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=""JavaScript"">alert("Hello World!!!")</SCRIPT>")



Comments (0)
Write comment
Your Contact Details:
Comment:
Security
Please input the anti-spam code that you can read in the image.

"