Call JavaScript function from code behind page in ASP.Net

Here, we learn how to Call JavaScript function from code behind page in ASP.Net.

First write javascript function in Head tag on HTML page.

<script type=”text/javascript” >
function AlertBox()
{

alert(‘Hello MeeraAcademy’);
}
</script>

Design ASP.Net web page with one button control:

Call JavaScript function from code behind page in ASP.Net
Call JavaScript function from code behind page in ASP.Net

Write below code on Button click event for call javascript function:

 protected void Button1_Click(object sender, EventArgs e)
{
Button1.Attributes.Add(“onclick”, “AlertBox()”);
}

The Output of call javascript function from code behind in asp.net is:

Call JavaScript function from code behind page in ASP.Net
Call JavaScript function from code behind page in ASP.Net

 

Leave a Reply

Your email address will not be published. Required fields are marked *