How to execute JavaScript Function from ASP.NET Code Behind

How to execute JavaScript Function from ASP.NET Code Behind:




You have a JavaScript function and you want to execute it from ASP.NET code behind file. You can achieve this by using RegisterStartupScript method of ClientScript class as shown below:

Following JavaScript function in your code:


<script type="text/javascript">

   function SayMeHello() {
      alert('Hello');
   }

</script>

In order to call it from code behind:


if (!ClientScript.IsStartupScriptRegistered("helloAlert"))
{
   Page.ClientScript.RegisterStartupScript(
      this.GetType(),
      "helloAlert",
      "SayMeHello();",
      true);

}




Other Related Post :





Comments

Popular posts from this blog