Call JavaScript from Asp.Net code behind

less than 1 minute read

Suppose you want to display confirmation message by javascript from asp.net code behind after saving data. Write the following code in your button event.

protected void btnSaved_Click(object sender, EventArgs e)
{
         string msg = "Data saved sucessfully"; 
         Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script type=text/javascript<alert('" + msg + "')</script>");
 
}