27 April, 2012

Call JavaScript from Asp.net code behind

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>");


}

No comments:

Post a Comment