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 *

9 + 3 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">