JavaScript Event Handler In ASP.NET June 11, 2022 Post a Comment I have the following iframe control (intended to be a facebook like button): Solution 1: asp.net events (like prerender) don't apply anywhere else (like javascript) assuming you are using jquery, I would wrap that in a $(), which is a shorthand for "Execute the following as soon as the page has loaded enough to start manipulating it". Also, asp.net controls have a different api then dom elements, so if you want to use that api you need to wrap it in a scriptlet tag <script type="text/javascript"> $(function () { var iframe = $("#likeButton"); var newSrc = iframe.attr("src"); newSrc += encodeURIComponent(location.href) + "<%= lblKey.Text %>"; iframe.attr("src", newSrc); }); </script> Copy Solution 2: Have you considered using the onload event and passing a reference to the iframe? <script type="text/javascript"> function change_source(iframe) { if (iframe.src.indexOf('facebook') < 0) { iframe.src = 'http://www.facebook.com/plugins/like.php?href=<%= lblKey.Text %>'; } } </script> Copy HTML something like this... <iframe id="likeButton" src="about:blank" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" onload="change_source(this);" </iframe> Copy Share Post a Comment for "JavaScript Event Handler In ASP.NET"
Post a Comment for "JavaScript Event Handler In ASP.NET"