How to call javascript function from ASP.NET Code behind with C#

It is very easy to call javascript function from code behind. Go by these steps

1. add this script in the aspx page.
    <script type="text/javascript">
        function SampleAlert() {
            alert("http://aspnettutorialonline.blogspot.com/");
        }
    </script>

2. Create a dynamic image button, and add properties. imgBtn.Attributes.Add("onlclick", "SimpleAlert()"); this will add the onclick property to the image button.

Oupput:
Calling Javascript function through image button
Calling Javascript function through image button


You can also register script like this.

        Page.ClientScript.RegisterStartupScript(this.GetType(),
            "alert", "SampleAlert();", true);

If you have any queries or suggestions, please feel free to ask in comments section.
Share this post :

Post a Comment

Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.

 
Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar