Articles → .NET → Call JavaScript from code behind in

Call JavaScript from code behind in

Software requirement

Prerequisite knowledge

Steps of execution

Create a new project

Picture showing the project structure of

Click to Enlarge

Add controls to the page

Picture showing the web page with the button control

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


Picture showing the alert message when user clicks on the button

Click to Enlarge

Picture showing the rendered script in view code

Click to Enlarge

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


Your Email Id  
Query/FeedbackCharacters remaining 250