Articles → .NET → Call JavaScript from code behind in asp.net

Call JavaScript from code behind in asp.net




















Software requirement





Prerequisite knowledge









Steps of execution













Create a new project





Click to Enlarge


Add controls to the page





Click to Enlarge


Add JavaScript code in code behind




using System;

public partial class _Default: System.Web.UI.Page {
	protected void Page_Load(object sender, EventArgs e) {

}
	protected void Button1_Click(object sender, EventArgs e) {
		this.ClientScript.RegisterStartupScript(this.GetType(), "ALERTMESSAGE", "alert('Button clicked')", true);
	}
}













Output



Click to Enlarge




Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Thursday, May 02, 2013

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250