It is very easy to call javascript function from code behind. Go by these steps
1. add this script in the aspx page.
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:
You can also register script like this.
If you have any queries or suggestions, please feel free to ask in comments section.
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 |
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.
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.