从后面的ASP.NET代码与iFrame交谈

Eti*_*nne 6 c# vb.net asp.net iframe facebook

我发现这个非常酷的页面允许你将facebook连接到你的网站:见这里

<iframe id="MyIframe" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.EXAMPLE.com%2F&amp;layout=button_count&amp;show_faces=true&amp;width=100&amp;action=recommend&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;" allowTransparency="true"></iframe>
Run Code Online (Sandbox Code Playgroud)

我希望能够在我的页面中调用这个iframe(我正在使用ASP.NET)并且我希望能够基于变量设置visibilty并且最重要的是我希望能够更改基于iframe的src在由变量构建的字符串上,根据页面的位置将"www.EXAMPLE.com"更改为另一个URL.

Rya*_*yes 21

尝试添加属性runat ="server".这应该允许您通过代码隐藏访问标记,这将允许您根据您的变量设置其他属性:

<iframe id="MyIframe" runat="server" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.EXAMPLE.com%2F&amp;layout=button_count&amp;show_faces=true&amp;width=100&amp;action=recommend&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;" allowTransparency="true"></iframe>
Run Code Online (Sandbox Code Playgroud)

这样,您就可以在代码后面按名称访问iframe.然后,您可以通过编写如下语句来操纵事物:

MyIframe.Visible = true;
Run Code Online (Sandbox Code Playgroud)

MyIframe.Attributes.Add("src", "http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.EXAMPLE.com%2F&amp;layout=button_count&amp;show_faces=true&amp;width=100&amp;action=recommend&amp;colorscheme=light&amp;height=21");
Run Code Online (Sandbox Code Playgroud)